Python 生成exe后出现Pyinstaller错误:ModuleNotFoundError:没有名为';cmath';

Python 生成exe后出现Pyinstaller错误:ModuleNotFoundError:没有名为';cmath';,python,pandas,pyinstaller,Python,Pandas,Pyinstaller,我很难将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/

我很难将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”,第1行,在
exec_模块中的文件“/Users/name/opt/anaconda3/lib/python3.7/site packages/PyInstaller/loader/pyimod03_importers.py”,第493行
exec(字节码、模块、指令)
文件“nsepython/\uuuuu init\uuuuuu.py”,第1行,在
exec_模块中的文件“/Users/name/opt/anaconda3/lib/python3.7/site packages/PyInstaller/loader/pyimod03_importers.py”,第493行
exec(字节码、模块、指令)
文件“nsepython/rahu.py”,第6行,在
exec_模块中的文件“/Users/name/opt/anaconda3/lib/python3.7/site packages/PyInstaller/loader/pyimod03_importers.py”,第493行
exec(字节码、模块、指令)
文件“pandas/\uuuuu init\uuuuuu.py”,第179行,在
exec_模块中的文件“/Users/name/opt/anaconda3/lib/python3.7/site packages/PyInstaller/loader/pyimod03_importers.py”,第493行
exec(字节码、模块、指令)
文件“pandas/testing.py”,第5行,在
exec_模块中的文件“/Users/name/opt/anaconda3/lib/python3.7/site packages/PyInstaller/loader/pyimod03_importers.py”,第493行
exec(字节码、模块、指令)
文件“pandas/_testing.py”,第27行,在
文件“pandas/_libs/testing.pyx”,第1行,在init pandas._libs.testing中
ModuleNotFoundError:没有名为“cmath”的模块
[74486]无法执行新脚本
注销
正在保存会话。。。
…复制共享历史。。。
…保存历史记录…截断历史记录文件。。。
…已完成。

我试图转换的文件名是new.py,它依赖于pandas,而pandas显然找不到名为cmath的模块。我该如何解决这个问题?我还需要构建一个exe吗?

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

cmath
是一个Python标准库模块,用于设计复杂的算法。所以它总是可用的。这可能是因为
pyinstaller
无法确定是否需要它,因此未将其包含在
.exe
中。查看
pyinstaller
文档,了解您是如何在
.spec
文件中提示它应该包含在内的。啊,是的,我知道了,您是对的@BoarGulesit说:名称错误:名称“cmath”未定义看起来熊猫的挂钩已更新为包含此导入: