1、常識pyinstaller.exe main.py --exclude-module PyQt5 將pyqt5模塊禁用,但是我的程序用到了pyqt5,所以運行時會產生找不到PyQt5模塊的錯誤。
2、在網上看到
找到 /Library/plugins路徑下的PyQt5文件夾,將裏面的dll動態庫pyqt5qmlplugin.dll複製出來
按照錯誤提示的路徑,一個個的新建文件夾,形成目錄C:\qt5b\qt_1524647842210\_h_env\Library\plugins,將剛纔複製出來的dll動態庫拷貝進去即可
沒有解決
3、在GitHub逛找到了解決方案,原來是pyinstall的bug。
最終修改方案。https://github.com/pyinstaller/pyinstaller/issues/3938
將~\anaconda3\Lib\site-packages\PyInstaller\utils\hooks\qt.py 文件中部分文件(頭尾沒改,具體位置找一下)改爲:
json_str = exec_statement("""
import sys
# exec_statement only captures stdout. If there are
# errors, capture them to stdout so they can be displayed to the
# user. Do this early, in case PyQt5 imports produce stderr
# output.
sys.stderr = sys.stdout
import json
from %s.QtCore import QLibraryInfo, QCoreApplication
# QLibraryInfo isn't always valid until a QCoreApplication is
# instantiated.
app = QCoreApplication([])
paths = [x for x in dir(QLibraryInfo) if x.endswith('Path')]
location = {x: QLibraryInfo.location(getattr(QLibraryInfo, x))
for x in paths}
try:
version = QLibraryInfo.version().segments()
except AttributeError:
version = None
print(str(json.dumps({
'isDebugBuild': QLibraryInfo.isDebugBuild(),
'version': version,
'location': location,
})))
""" % self.namespace)