1. 程式人生 > >使用pyinstaller把py檔案打包為exe檔案

使用pyinstaller把py檔案打包為exe檔案

注:安裝pyinstall的先決條件是安裝PyWin32

pyinstall下載及安裝

下載地址:

pip install pyinstall

若是下載的安裝包,則下載解壓後進入cmd命令,cd pyinstall檔案目錄中執行 python setup.py install 即可安裝

安裝完成後,使用如下命令可以確認版本號:

pyinstaller --version

如果顯示Error: Python 2.6+ on Windows support need pywin32,則說明當前沒有安裝pywin32,安裝後即可正常執行PyInstaller。 

安裝pywin32時需要注意,pywin32的版本和本機Python位數和版本必須相同。


pyinstall使用

寫好的一個dif.py檔案(在這個目錄下e:\test\dif.py),釋出單個可執行檔案也就是.exe使用-F

用cmd進入PyInstaller的目錄 然後執行以下命令:

python  pyinstaller.py -F  e:\test\dif.py​

用cmd進入專案目錄(e:\test)執行以下命令:

pyinstall dif.py -F

指定dist生成目錄路徑(而不是命令行當前目錄)

pyinstaller -F d:/test/dif.py​ --distpath=E:/test/dist

為生成的exe加上圖示

pyinstaller -F d:/test/dif.py​ --distpath=E:/test/dist -i d:/test/test.ico


---------------------------------------------------------------------------------------------------------------------------------------------------------

執行錯誤

在本地可成功執行打包成的exe檔案;在其他電腦上運作則出現閃退情況。

檢查錯誤

-------------------------------------------------------------------------------------------------------------------------------------------------------------

error1:‘service’ object has no attribute ‘process’


解決方法:

2.把該目錄路徑新增到環境變數path中,如:C:\Program Files\Internet Explorer

------------------------------------------------------------------------------------------------------------------------------------------------------------

error2:Protected Mode settings are not the same for all zones


解決方法:

開啟IE瀏覽器 設定ie的Internet選項-安全-Internet/本地Internet/受信任的站點/受限制的站點下的啟用保護模式的設定需要一致


error3:browser zoom level was set to 125% it should be set to 100%


解決方法:

開啟瀏覽器設定瀏覽器的縮放比例為100%