用pyinstaller打包python pyqt5程序時錯誤:Cannot find existing PyQt5 plugin directories

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)
發佈了2 篇原創文章 · 獲贊 0 · 訪問量 502
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章