我正在使用Python 3.7.3和PyInstaller 4.0,并且在Windows 10上操作。我的脚本如下:
import pandas as pd
print('hello')
但是当我尝试运行.exe文件时,出现了一个错误。
到目前为止,我已经尝试了以下方法:
pyinstaller --hidden-import=pandas --onefile myscript.py
但是它不起作用。我还更新到了这里的当前开发版本:https://pyinstaller.readthedocs.io/en/stable/installation.html 此外,我编辑了.spec文件并写入:
# -*- mode: python -*-block_cipher = Nonedef get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_patha = Analysis(['FIFA.py'],
pathex=['C:\\Users\\NBenton\\PycharmProjects\\RES3D_BETA'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
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,
a.binaries,
a.zipfiles,
a.datas,
name='FIFA',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
然后运行
pyinstaller myscript.spec --onefile
我知道这是一个常见的问题,但其他问题中的答案对我不起作用。
有什么帮助吗?谢谢
经过很多行,错误是:
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\hooks\hook-numpy.core.py", line 29, in <module>
pkg_base, pkg_dir = get_package_paths('numpy.core')
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 528, in get_package_paths
file_attr = get_module_file_attribute(package)
File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 330, in get_module_file_attribute
raise ImportError
ImportError
hook-pandas.py
文件长什么样? - It_is_Chris\AppData\Local\Programs\Python\Python36\Lib\site-packages\PyInstaller\hooks
的位置。 - It_is_Chris