我正在尝试使用适用于 Windows 的 PyInstaller(开发版)将 Python 脚本包装到 exe 中。
该脚本使用 Pandas,我在运行 exe 时遇到了错误。
Traceback (most recent call last): File "site-packages\pandas__init__.py", line 26, in <module> File "C:\Users\Eddie\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:\Users\Eddie\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 "G5k Version file Extract (with tkinter).py", line 15, in <module> File "C:\Users\Eddie\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.
我试过为没有熊猫的程序做这件事,一切都很好。
这与 Python 2 已经解决的 另一个问题 非常相似,但我使用的是 Python 3,由于 .spec 文件格式发生了变化,该解决方案并不适用于相同的方式。
Python 3.6
PyInstaller - 版本 3.3
熊猫 - 版本 0.20.3
原文由 Eduard Fidler 发布,翻译遵循 CC BY-SA 4.0 许可协议
PyInstaller 3.3、熊猫 0.21.0、Python 3.6.1。
由于尚未发布/提交的 PyInstaller 修复,我能够解决这个问题,请参阅 this 和 this 。并保持将其打包到一个可执行文件中的能力。
基本上:
找到 PyInstaller 文件夹..\hooks,例如
C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks
。使用内容(或基于您的错误的任何类似内容)创建文件 hook-pandas.py:
保存 + 我删除了 .spec 文件、build 和 dist 文件夹以确保安全。
运行
pyinstaller -F my_app.py
。只要您不升级或重新安装 PyInstaller,此修复程序就应该有效。所以你不需要编辑 .spec 文件。
也许他们会尽快为我们提供修复! :)