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!"
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')
I then ran:
$pyinstaller Hello.spec --onefile
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.
This is similar to the answer here: Pyinstaller not correclty importing pycripto... sometimes
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…