歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> PyInstaller 來建立Linux下的Python獨立執行文件

PyInstaller 來建立Linux下的Python獨立執行文件

日期:2017/2/28 16:04:27   编辑:Linux教程

以下內容假定已安裝好Python 2.4/2.5

一、下載並編譯pyinstaller(只需做一次,以後可直接做第二步)

1.下載pyinstaller,現在的版本是1.3
(1)wget http://pyinstaller.hpcf.upr.edu/source/1.3/pyinstaller_1.3.tar.gz

2.解包進入源碼目錄
(1)tar zxv pyinstaller_1.3.tar.gz
(2)cd pyinstaller-1.3/source/linux

3.編譯源代碼
(1)python Make.py 生成python的 .pyc文件

如無錯誤,則出現如下提示(只有一行):
Now run "make" to build the targets: ../../support/loader/run ../../support/loader/run_d

(2)make 連接生成linux的 .o 文件

4.生成編譯配置文件
(1)python Configure.py 生成config.dat配置文件


二、編譯獨立運行的python可執行文件

1.生成spec文件
python pyinstaller-1.3/Makespec.py --onefile --upx linuxlaptop.py

參數說明:
--onefile 生成單文件
--upx 生成壓縮的文件(可減小執行文件體積,需先安裝upx軟件包)


2.生成最終的可執行文件
python pyinstaller-1.3/Build.py linuxlaptop.spec

Copyright © Linux教程網 All Rights Reserved