【问题标题】:Pyinstaller Error after exe built: ModuleNotFoundError: No module named 'cmath'exe 构建后的 Pyinstaller 错误:ModuleNotFoundError: No module named 'cmath'
【发布时间】:2020-12-27 20:31:29
【问题描述】:

我很难将我的 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吗?

【问题讨论】:

  • cmath 是一个 Python 标准库模块,用于解复杂算术。所以它总是可用的。可能是pyinstaller 无法确定需要它,因此没有将其包含在.exe 中。查看pyinstaller 文档,了解您如何在.spec 文件中暗示应该包含它。
  • 啊,是的,我想通了,你是对的@BoarGules

标签: python pandas pyinstaller


【解决方案1】:

--hidden-import cmath 添加到 pyinstaller 运行中。

【讨论】:

猜你喜欢
  • 2022-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-05
  • 1970-01-01
  • 2022-10-13
  • 2022-08-14
  • 2015-04-30
相关资源
最近更新 更多