我正在使用Pyinstaller将Python编译为独立的可执行文件。源代码包括PySide和SqlAlchemy模块。 PyInstaller创建的dist .exe运行正常,但是当我运行访问数据库的命令时,我在命令提示符中得到了这个错误代码:
Traceback (most recent call last):
File "clipper_tree.py", line 1907, in add_tree
File "build\bdist.win-amd64\egg\sqlalchemy\sql\operators.py", line 304, in __eq__
File "build\bdist.win-amd64\egg\sqlalchemy\orm\attributes.py", line 175, in operate
File "build\bdist.win-amd64\egg\sqlalchemy\sql\operators.py", line 304, in __eq__
File "build\bdist.win-amd64\egg\sqlalchemy\orm\properties.py", line 270, in operate
File "build\bdist.win-amd64\egg\sqlalchemy\sql\annotation.py", line 95, in __eq__
File "build\bdist.win-amd64\egg\sqlalchemy\sql\operators.py", line 304, in __eq__
File "build\bdist.win-amd64\egg\sqlalchemy\sql\elements.py", line 686, in operate
File "build\bdist.win-amd64\egg\sqlalchemy\sql\operators.py", line 304, in __eq__
File "<string>", line 1, in <lambda>
File "build\bdist.win-amd64\egg\sqlalchemy\sql\type_api.py", line 62, in operate
File "build\bdist.win-amd64\egg\sqlalchemy\util\langhelpers.py", line 964, in __getattr__
File "build\bdist.win-amd64\egg\sqlalchemy\util\langhelpers.py", line 962, in __getattr__
ImportError: Could not resolve module sqlalchemy.sql.default_comparator
编译时,命令提示符输出一些警告,说明无法找到与sql炼金术相关的“隐藏DLL”。它说它正在删除sqlalchemy / test文件作为回应。这里的任何帮助都将深表感谢。
答案 0 :(得分:4)
我之前有同样的问题..通过在我的主程序上导入sqlalchemy.sql.default_comparator解决了这个问题..
答案 1 :(得分:0)
正如@fredpi 所说,您可以将模块添加到您尝试编译的 python 文件的 .spec 文件中的 hiddenimports
初始值设定项的 Analysis
参数中。像这样:hiddenimports=['sqlalchemy.sql.default_comparator']
确保在运行 pyinstaller 时运行传递 .spec 文件,否则它会覆盖 .spec 文件并且您的更改将丢失。例如:pyinstaller.exe --onefile myscript.spec