pip install pyinstaller
pip install --upgrade pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
pyinstaller 安裝方法2
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn pyinstaller==4.1
python setup.py build
python setup.py install
pip show pyinstaller
# -F -D互斥參數
-F 打包成一個exe文件,小項目可以採用,打開比較慢,多個.py打包時不能使用
-D 默認參數,打包結果放入到創建的文件夾中,可以看到裡面有很多的依賴文件
# -w -c互斥參數
-w 使用項目的GUI界面,無cmd控制臺
-c 默認參數,使用cmd控制臺 如果打包文件執行報錯,可嘗試用-c 顯示控制臺
-n 執行項目的名稱,默認.py的文件名
-i 將ico圖標打包到exe文件中
--hidden-import 打包時導包信息
# 打包PyQt項目強烈建議 帶上以下參數
--hidden-import PyQt5.sip
# 打包命令示例
# 在項目的根目錄下執行打包命令
pyinstaller -w xxx.py --hidden-import PyQt5.sip
# 打包結果輸出在項目根目錄下的 dist文件夾中
# 不建議使用 -F打包成一個exe文件 所謂:打包一時爽,打開5秒鐘
# 非-F命令下, 靜態資源、建好的Sqlite資料庫可以直接放入dist中 生成的文件夾中
python 轉換exe 文件
pyinstaller -F **.py(目標程序) -i **.icon(目標圖標) -p **\site-packages\ (程序的site-package第三方庫) -p **\Lib\ (anaconda的python的庫)
python pyinstaller.py -F pic-txt1.py -i D:\PYTHON\pyinstaller-4.1\1.ico
相關指令
D:\>where python
D:\Anaconda3\python.exe
D:\>python -V
Python 3.6.4 :: Anaconda custom (64-bit)
D:\>pip -V
pip 21.0 from D:\Anaconda3\lib\site-packages\pip-21.0-py3.6.egg\pip (python 3.6)
python 標準庫位置:%python安裝路徑%\Lib
第三方庫位置:%python安裝路徑%\Lib\site-packages
pip 文件安裝
python setup.py install
用戶變量-備份:
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps
C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\Lib\site-packages