PyInstaller和Pandas [英] PyInstaller and Pandas
问题描述
我有一个非常简单的Python模块,正在尝试将其编译为Windows .exe文件.在我的脚本中,我正在使用wxPython和Pandas库.当从我的模块中排除了Pandas库时,仅 生成的PyInstaller .exe文件可以工作/打开.
I have a fairly simple Python module that I am trying to compile into a Windows .exe file. In my script I am using the wxPython and Pandas libraries. The PyInstaller .exe file that is generated only works/opens when the Pandas library is excluded from my module.
无论在PyInstaller中使用--onefile
还是--onedir
,我都遇到相同的问题.我在网上发现PyInstaller(2.1)的新"版本应该已经解决了该错误.有人对做什么有任何想法吗?
I am getting the same issue whether I use --onefile
or --onedir
in PyInstaller. I found online that the "new" version of PyInstaller (2.1) should have taken care of this bug. Does anyone have any ideas on what to do?
PyInstaller: version 2.1
pandas: version 0.15.2
Python: version 2.7
推荐答案
我遇到了同样的问题.我将其简化为像Hello.py这样的简单脚本:
I ran into the same issue. I boiled it down to a simple script like this Hello.py:
import pandas
print "hello world, pandas was imported successfully!"
要使熊猫在运行时正确导入,我必须将Hello.spec修改为以下内容:
To get pandas to import at run-time correctly I had to modify the Hello.spec to the following:
# -*- mode: python -*-
block_cipher = None
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
a = Analysis(['Hello.py'],
pathex=['C:\\ScriptsThatRequirePandas'],
binaries=None,
datas=None,
hiddenimports=[],
hookspath=None,
runtime_hooks=None,
excludes=None,
win_no_prefer_redirects=None,
win_private_assemblies=None,
cipher=block_cipher)
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)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='Hello',
debug=False,
strip=None,
upx=True,
console=True )
scoll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=None,
upx=True,
name='Hello')
然后我跑了
$pyinstaller Hello.spec --onefile
在命令提示符下输入
并得到了我所期望的"hello world"消息.我仍然不完全理解为什么这样做是必要的.我有一个自定义的熊猫版本-已挂接到MKL库中-但是我不清楚这是否导致运行失败.
from the command prompt and got the 'hello world' message I expected. I still don't completely understand why this is necessary. I have a custom build of pandas - which is hooked into the MKL libraries - but it isn't clear to me that this is causing the run failure.
这类似于此处的答案: Pyinstaller不正确地导入pycripto ...有时
This is similar to the answer here: Pyinstaller not correclty importing pycripto... sometimes
这篇关于PyInstaller和Pandas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!