我很难将我的 Python 代码转换为 exe。在我使用 pyinstaller 将我的代码转换为 exe 后,它给我一个错误,提示我在运行它时缺少导入。这是完整的日志:
Traceback (most recent call last):
File "new.py", line 1, in <module>
File "/Users/name/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "nsepython/__init__.py", line 1, in <module>
File "/Users/name/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "nsepython/rahu.py", line 6, in <module>
File "/Users/name/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pandas/__init__.py", line 179, in <module>
File "/Users/name/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pandas/testing.py", line 5, in <module>
File "/Users/name/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pandas/_testing.py", line 27, in <module>
File "pandas/_libs/testing.pyx", line 1, in init pandas._libs.testing
ModuleNotFoundError: No module named 'cmath'
[74486] Failed to execute script new
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
我要转换的文件的名称是 new.py,它依赖于显然找不到名为 cmath 的模块的 Pandas。我该如何解决?无论如何我可以构建一个exe吗?
答案 0 :(得分:5)
将 --hidden-import cmath
添加到 pyinstaller 运行中。