【问题标题】:Issues with freezing Python Pandas冻结 Python Pandas 的问题
【发布时间】:2018-04-19 13:33:30
【问题描述】:

我刚刚从 Python 2.7 升级到 3.6。 我有一个带有 GUI 的相当大的脚本,我已经用 pyinstaller 将它冻结为一个 .exe 文件。

我现在对 .py 脚本进行了一些更改,在我冻结它之前它可以与新的 Python 版本一起使用。

但是,当我冻结时,我收到“无法执行脚本”消息。 我试图查看错误代码并将问题追溯到 Pandas 模块。这是错误消息:

C:\Users\MRCH\dist>My_File.exe
Traceback (most recent call last):
  File "site-packages\pandas\__init__.py", line 26, in <module>
  File "c:\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pandas\_libs\__init__.py", line 4, in <module>
  File "c:\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
    module = loader.load_module(fullname)
  File "pandas/_libs/tslib.pyx", line 1, in init pandas._libs.tslib
ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "My_File.py", line 6, in <module>
  File "c:\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pandas\__init__.py", line 35, in <module>
ImportError: C extension: No module named 'pandas._libs.tslibs.timedeltas' not built. 
**If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.**
[2032] Failed to execute script My_File

错误信息建议先运行'python setup.py build_ext --inplace --force'来导入pandas。我会在哪里运行这个? cmd运行找不到setup.py文件?

【问题讨论】:

  • 您是否尝试过将此模块添加到 hiddenimports 列表中?这可以作为参数添加到 .spec 文件 hiddenimports = ['pandas._libs.tslibs.timedeltas'] 或命令行中。如果您编辑 .spec 文件,请确保将 pyinstaller 运行为:pyinstaller myfile.spec 这可能是一个更容易尝试的选项,而不是错误消息中建议的方法。
  • @apogalacticon 是正确的。您需要为 pyinstaller 创建一个类似于 hiddenimports = ['pandas._libs.tslibs.timedeltas']hook-pandas.py 文件,只需将挂钩添加到 pyinstaller 挂钩文件夹即可。

标签: python pandas pyinstaller


【解决方案1】:

@apogalacticon 谢谢!

在 .spec 文件中添加以下行解决了问题:

hiddenimports = ['pandas._libs.tslibs.timedeltas'] 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多