PyInstaller和Pandas

bsh*_*ehy 17 python pyinstaller pandas

我有一个相当简单的Python模块,我试图编译成Windows .exe文件.在我的脚本中,我使用的是wxPython和Pandas库.生成的PyInstaller .exe文件在从我的模块中排除Pandas库时才能工作/打开.

无论是使用--onefile还是--onedirPyInstaller,我都遇到了同样的问题.我在网上发现PyInstaller(2.1)的"新"版本应该处理这个bug.有没有人对如何做有任何想法?

PyInstaller: version 2.1
pandas: version 0.15.2
Python: version 2.7
Run Code Online (Sandbox Code Playgroud)

phy*_*ory 19

我遇到了同样的问题.我把它归结为一个像Hello.py这样的简单脚本:

import pandas
print "hello world, pandas was imported successfully!"
Run Code Online (Sandbox Code Playgroud)

要在运行时正确导入pandas,我必须将Hello.spec修改为以下内容:

# -*- 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')
Run Code Online (Sandbox Code Playgroud)

然后我跑了:

$pyinstaller Hello.spec --onefile
Run Code Online (Sandbox Code Playgroud)

从命令提示符,我得到了'hello world'消息.我仍然不完全理解为什么这是必要的.我有一个自定义构建的pandas - 它连接到MKL库 - 但我不清楚这是否导致运行失败.

这与答案类似:Pyinstaller没有关联导入pycripto ...有时候


Joh*_*ohn 11

我有一个与pyinstaller版本3.3类似的问题.解决方案是这里描述一个缺少hiddenimport钩子

我创建了一个新的文件Pyinstaller下/钩/被叫hook-pandas.py和本提交描述把内容在这里通过Python手动和重新安装pyinstaller的setup.py在Pyinstaller目录中安装.

当我使用-onefile选项使用pyinstaller从我的pandas脚本创建exe时,问题没有重现.

  • 这对我有用,尽管我不必重新安装Pyinstaller。 (2认同)

小智 5

就像另一种解决方案一样,添加命令--hidden-import=pandas._libs.tslibs.timedelta中缺少的模块或任何模块pyinstaller也可以。

如果您不想接触 pyinstaller 的源代码,这可能会有所帮助。