安裝qt:
http://download.qt.io/archive/qt/
安裝pyqt designer:
https://pypi.org/project/PyQt5Designer/
更新Pip:
python -m pip install –upgrade pip
moudle_name:是對應的模組名;請自行更換為自己需要更新的模組名
檢視所有可更新的模組: pip list –outdated
更新某一個模組: pip install –upgrade module_name
指定更新源更新模組 pip install –upgrade -i https://pypi.douban.com/simple moudle_name
安裝對應的模組: pip install pip-review
更新所有的模組: pip-review –local –interactive
pip install PyQt5
pip3 install PyQt5-sip
pip3 install pyqtdeploy
pip3 install QScintilla
pip3 install PyQtWebEngine
pip3 install PyQtDataVisualization
pip3 install PyQtChart
pip3 install PyQt3D
pip3 install pyinstaller
pip3 install PyQtPurchasing
pyqt5-stub
打包:
其他SIL用到的依賴:
pip install numpy
其中必須要指定特定版本,否則會報 no module named ‘numpy.random.common’
pip uninstall numpy
pip install numpy==1.16.2
pip install pywin32
虛擬環境也必須裝有:
pip install virtualenv
pip install virtualenvwrapper-win
建立虛擬環境 啟用虛擬環境:
cd c:/pyenv
python3 -m venv pyqt5venv
cd pyqt5venv/Scprits
source activate
如果是win,就到對應目錄執行
activate.bat
遇到無法啟用時,是因為power shell的許可權問題
因為PowerShell預設不允許執行*.ps1指令碼檔案,所以首先需要開啟許可權。
以管理員身份啟動PowerShell,並執行Set-ExecutionPolicy RemoteSigned,可以使用TAB鍵自動補全。
PS C:\WINDOWS\system32> Set-ExecutionPolicy RemoteSigned
執行一遍後就可以了
打包:
cd /c/Users/kingdelee/PycharmProjects/SIL/src/py
pyinstaller -F -w Main.py
安裝依賴:
pip install PyQt5
pip install pyinstaller
坑爹問題解決:
參考:
1.
不適用虛擬環境的時候出現的問題解決:
1.用360安裝,微軟常用執行庫合集64位,可以解決 dll錯誤的情況
2..新增path也可以解決dll找不到的情況
建立PyQT5_HOME:
C:\Python\Python37\Lib\site-packages\PyQt5\Qt
加入到Path中
${PyQT5_HOME}/bin
使用虛擬環境時出現的問題解決:
1.pyinstaller本身問題:
下載bindepend.py 並替換
C:\pyenv\pyqt5venv\Lib\site-packages\PyInstaller\depend 中對應檔案
下載地址:
https://github.com/Loran425/pyinstaller/tr...
Traceback (most recent call last):
File "C:\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\pyenv\pyqt5venv\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "c:\pyenv\pyqt5venv\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\pyenv\pyqt5venv\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\pyenv\pyqt5venv\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\pyenv\pyqt5venv\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
exec(text, spec_namespace)
File "<string>", line 32, in <module>
File "c:\pyenv\pyqt5venv\lib\site-packages\PyInstaller\building\api.py", line 424, in __init__
strip_binaries=self.strip, upx_binaries=self.upx,
File "c:\pyenv\pyqt5venv\lib\site-packages\PyInstaller\building\api.py", line 196, in __init__
self.__postinit__()
File "c:\pyenv\pyqt5venv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "c:\pyenv\pyqt5venv\lib\site-packages\PyInstaller\building\api.py", line 273, in assemble
pylib_name = os.path.basename(bindepend.get_python_library_path())
File "C:\Python\Python37\lib\ntpath.py", line 214, in basename
return split(p)[1]
File "C:\Python\Python37\lib\ntpath.py", line 183, in split
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
使用upx:
下載:
https://github.com/upx/upx
解壓到
c:\Tools\upx
打包的時候使用upx:
pyinstaller
https://github.com/upx/upx
UPX報錯:
解決:
https://jingyan.baidu.com/article/a681b0de...
https://www.fixdown.com/soft/1921.html
https://zhidao.baidu.com/question/50137916...
https://www.jianshu.com/p/c1e75244b6f3/
打包詳細說明:
https://blog.csdn.net/weixin_42052836/arti...
https://blog.csdn.net/polyhedronx/article/...
https://blog.csdn.net/oh5W6HinUg43JvRhhB/a...
https://www.jianshu.com/p/cc76099bbe04
https://blog.csdn.net/polyhedronx/article/...
https://blog.csdn.net/oh5W6HinUg43JvRhhB/a...
使用spec方式打包
先生成 spec檔案:
pyi-makespec -w Main.py
編輯spec檔案:
# -*- mode: python -*-
import os
import sys
sys.setrecursionlimit(5000)
path = 'C:\\Users\\kingdelee\\PycharmProjects\\SIL\\src\\py'
print("-----------path:" + path)
# 'C:\\Users\\kingdelee\\PycharmProjects\\SIL\\src\\py'
block_cipher = None
resources = [(path + '\\resources\\pic', 'resources\\pic'), (path + '\\resources\\doc', 'resources\\doc')]
iconPath = path + '\\CSEI_logo.ico'
a = Analysis(['Main.py'],
pathex=[path],
binaries=[],
datas=resources,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='SIL',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False,
icon=iconPath)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='Main')
打包成很多檔案:
pyinstaller -D Main.spec
打包成單個exe檔案:
pyinstaller -F -c Main.spec
用於定義python原始檔,包括搜尋路徑和原始檔名等。
① scripts:在Analysis中定義的原始檔;
② pure:python模組;
③ binaries:動態庫;
④ datas:資料檔案,包括圖片字型等;
⑤ zipfiles:zip格式的依賴檔案,一般是egg格式的庫檔案。
PYZ:
將python檔案壓縮打包,包含程式執行需要的所有依賴,輸入一般是Analysis.pure。
EXE:
打包生成exe檔案,根據上面兩項生成。EXE子任務包括Analysis的所有5個輸出項以及程式執行所需的一些配置檔案和動態庫。
配置檔案和動態庫通過TOC格式來配置,格式為(name, path, typecode),例如:
typecode包括:
① EXTENSION:python擴充套件庫;
② PYSOURCE:python指令碼;
③ PYMODULE;
④ PYZ;
⑤ PKG;
⑥ BINARY:動態庫;
⑥ DATA:資料檔案;
⑦ OPTION。
COLLECT:
用來構建最終的生成目錄,可以複製其他子任務生成的結果,並拷貝到指定目錄,形成最終的打包結果,COLLECT也可以沒有。
打包看到控制檯
引數 | 含義 |
---|---|
-F | 指定打包後只生成一個exe格式的檔案 |
-D | –onedir 建立一個目錄,包含exe檔案,但會依賴很多檔案(預設選項) |
-c | –console, –nowindowed 使用控制檯,無介面(預設) |
-w | 去除控制檯,建議在開發gui的時候使用 |
-i | 改變生成程式的icon圖示 |
pyinstaller -F -c Main.py
win7 打包 unable to find Qt5Core.dll on PATH
問題:
解決:
no module named ‘numpy.random.common’
其中必須要指定特定版本,否則會報 no module named ‘numpy.random.common’
pip uninstall numpy
pip install numpy==1.16.2
本作品採用《CC 協議》,轉載必須註明作者和本文連結