Python PyInstaller 中没有名为“pandas._libs.tslibs.timedeltas”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47318119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No module named 'pandas._libs.tslibs.timedeltas' in PyInstaller
提问by Eduard Fidler
I am trying to wrap a Python script into an exe using PyInstaller (development version) for windows.
我正在尝试使用 Windows 的 PyInstaller(开发版)将 Python 脚本包装到 exe 中。
The script uses Pandas and I have been running into an error when running the 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.
I have tried doing this for programs without pandas and everything was fine.
我试过为没有熊猫的程序这样做,一切都很好。
This is very similar to another questionalready solved for Python 2, but I am using Python 3 and that solution does not apply the same way due to the changed .spec file format.
这与Python 2 已经解决的另一个问题非常相似,但我使用的是 Python 3,并且由于 .spec 文件格式的更改,该解决方案不适用相同的方式。
Python 3.6
PyInstaller - version 3.3
Pandas - version 0.20.3
Python 3.6
PyInstaller - 版本 3.3
Pandas - 版本 0.20.3
回答by Petr Szturc
PyInstaller 3.3, Pandas 0.21.0, Python 3.6.1.
PyInstaller 3.3、Pandas 0.21.0、Python 3.6.1。
I was able to solve this thanks to not-yet published/committed fix to PyInstaller, see thisand this. AND keeping the ability to pack it into one executable file.
由于尚未发布/提交对 PyInstaller 的修复,我能够解决这个问题,请参阅this和this。并保持将其打包成一个可执行文件的能力。
Basically:
基本上:
Locate PyInstaller folder..\hooks, e.g.
C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks
.Create file hook-pandas.py with contents (or anything similar based on your error):
hiddenimports = ['pandas._libs.tslibs.timedeltas']
Save it + I deleted .spec file, build and dist folders just to be sure.
Run
pyinstaller -F my_app.py
.
找到 PyInstaller 文件夹..\hooks,例如
C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks
。使用内容(或基于您的错误的任何类似内容)创建文件 hook-pandas.py:
hiddenimports = ['pandas._libs.tslibs.timedeltas']
保存 + 我删除了 .spec 文件、build 和 dist 文件夹只是为了确定。
运行
pyinstaller -F my_app.py
。
This fix should work as long as you don't upgrade or reinstall PyInstaller. So you don't need to edit .spec file.
只要您不升级或重新安装 PyInstaller,此修复程序就应该起作用。所以你不需要编辑 .spec 文件。
Maybe they will include the fix sooner for us! :)
也许他们会更快地为我们提供修复程序!:)
回答by Simon
I'm not sure it may help you but following the solution on the post you mention work for me with python 3.6 pyinstaller 3.3 and pandas 0.21.0 on windows 7.
我不确定它可能对您有帮助,但是按照您提到的帖子中的解决方案在 Windows 7 上使用 python 3.6 pyinstaller 3.3 和 pandas 0.21.0 对我有用。
So adding this to the spec file just after analysis :
因此,在分析后将其添加到规范文件中:
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
Also my spec file format is the same as the one in the post you mention.
回答by Stephan
I managed to solve this problem by using the "--hidden-import" flag. Hopefully this can be helpful to someone else that comes across this thread.
我设法通过使用“--hidden-import”标志解决了这个问题。希望这对遇到此线程的其他人有所帮助。
pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas myScript.py
回答by Srini
If you are using Anaconda, it is highly likely that when you were trying to uninstall some package it has disrupted pandas dependency and unable to get the required script. If you just run conda install pandas
you might end up with another error:
如果您使用的是 Anaconda,则很有可能在您尝试卸载某个软件包时,它破坏了 Pandas 的依赖关系并且无法获得所需的脚本。如果你只是运行,conda install pandas
你可能会遇到另一个错误:
module 'pandas' has no attribute 'compat'
.
module 'pandas' has no attribute 'compat'
.
So, try uninstalling and reinstalling pandas conda uninstall pandas
, Install it again using conda install pandas
this will solve the problem.
On the other hand, if you are not using Anaconda., try doing the same on Command prompt pointing to Python scripts folder pip uninstall pandas & pip install pandas
.
因此,尝试卸载并重新安装 pandas conda uninstall pandas
,使用conda install pandas
此方法重新安装即可解决问题。另一方面,如果您没有使用 Anaconda,请尝试在指向 Python 脚本文件夹的命令提示符下执行相同操作pip uninstall pandas & pip install pandas
。
Most of the times, this should solve the problem. Just to be cover all the possibilities, don't forget to Launch Spyder from Anaconda after installing pandas.
大多数情况下,这应该可以解决问题。只是为了涵盖所有的可能性,不要忘记在安装 Pandas 后从 Anaconda 启动 Spyder。