Edu*_*ler 23 python windows pyinstaller python-3.x pandas
我正在尝试使用PyInstaller(开发版)为Windows将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.
Run Code Online (Sandbox Code Playgroud)
我试过没有大熊猫的程序这样做,一切都很好.
这与已经为Python 2解决的另一个问题非常相似,但我使用的是Python 3,并且由于更改的.spec文件格式,该解决方案不会以相同的方式应用.
Python 3.6
PyInstaller - 版本3.3
Pandas - 版本0.20.3
Pet*_*urc 48
PyInstaller 3.3,Pandas 0.21.0,Python 3.6.1.
我能解决这个问题由于尚未公布/致力于修复程序PyInstaller,看到这个和这个.并保持将其打包成一个可执行文件的能力.
Basicly:
找到PyInstaller文件夹..\hooks,例如C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks
.
使用内容(或基于您的错误的任何类似内容)创建文件hook-pandas.py:
hiddenimports = ['pandas._libs.tslibs.timedeltas']
Run Code Online (Sandbox Code Playgroud)保存它+我删除.spec文件,构建和dist文件夹只是为了确定.
跑 pyinstaller -F my_app.py.
只要您不升级或重新安装PyInstaller,此修复程序就可以正常工作.因此您无需编辑.spec文件.
也许他们会尽快为我们提供修复!:)
小智 12
我不确定它可能会对你有所帮助,但是在你提到的工作上你使用python 3.6 pyinstaller 3.3和pandas 0.21.0在Windows 7上工作.
因此,在分析后将其添加到spec文件中:
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)
Run Code Online (Sandbox Code Playgroud)
小智 6
我设法通过使用"--hidden-import"标志来解决这个问题.希望这对遇到这个帖子的其他人有帮助.
pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas myScript.py
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22571 次 |
最近记录: |