Win7,64位下,PyInstaller把.py生成.exe時,要使用低版本的setuptools(19.2)
使用PyInstaller,能把Python的*.py打包生成脫離Python平臺的可執行程式*.exe。
需要先安裝pywin32,再安裝PyInstaller。
而且生成.exe時,要使用低版本的setuptools(19.2)
1、安裝pywin32
下載pywin32-220.win-amd64-py3.5.exe
安裝過程:
2、安裝PyInstaller
下載PyInstaller-3.2.zip解壓安裝
出現錯誤。
換一個,下載PyInstaller-3.0.zip解壓安裝
安裝成功!
Python指令碼test.py 檔案,放在D:\PyInstaller-3.0目錄下。
3、打包生成帶控制檯的* .exe
D:\PyInstaller-3.0>python pyinstaller.py --console --onefile test.py
命令執行成功後,在D:\PyInstaller-3.0下會生成一個test資料夾。在這個test資料夾下有一個名為dist的資料夾,此資料夾下有生成好的test.exe。
4、打包生成帶GUI的* .exe
把圖示檔案my.ico,放在D:\PyInstaller-3.0目錄下。複製test.py,並重命名test2.py
D:\PyInstaller-3.0>python pyinstaller.py -w --onefile --icon="my.ico" test2.py
命令執行成功後,在D:\PyInstaller-3.0下會生成一個test2資料夾。在這個test2資料夾下有一個名為dist的資料夾,此資料夾下有生成好的test2.exe。
5、執行生成的*.exe
點選test2.exe,彈出錯誤:
原因是:setuptools包的版本太高,環境裡的setuptools版本是20.10.1,只有低版本的setuptools(19.2)才能正常工作。
pip list
解除安裝setuptools(20.10.1):
pip uninstall setuptools
安裝低版本的setuptools(19.2):
下載setuptools-19.2.zip後,在cmd介面,切換到解壓後的setuptools19.2資料夾,執行“python ez_setup.py”即可。
pip list
安裝成功。
再點選test2.exe,顯示出圖形:
參考: