首先為啥說一定要注明是python3.7呢。因為之前的版本不支持pyinstaller
環境:pycharm2018.3+win7+python3.7
工具:pyinstaller
1、使用pycharm安裝pyinstaller,此處不寫詳細步驟,參考:https://jingyan.baidu.com/article/335530dafdbb3619cb41c3a8.html
找到pyinstaller安裝即可。
2、找到pyinstaller的安裝目錄。
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyInstaller
備注:根據自己安裝的包的路徑來定,我的是在這里
如果找不到,可以用下面的方法找到自己安裝包的路徑
3、將我們要打包的程序copy至pyinstaller的安裝目錄下:
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyInstaller
4、打開cmd,找到該路徑 cd C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyInstaller,輸入命令pyinstaller -F *.py
該命令會將所有的依賴放到一個文件夾中。相當於-F的解壓
如下圖顯示,打包成功
5、此時在Scripts的目錄下能夠看到已經生成的dist目錄和*.spec文件。運行*.exe文件即可。