我使用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.ioenstableinstallation.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
添加 datas = collect_data_files('pandas')
至 hook-pandas.py
文件为我工作
from PyInstaller.utils.hooks import collect_submodules
from PyInstaller.utils.hooks import collect_data_files
# Pandas keeps Python extensions loaded with dynamic imports here.
hiddenimports = collect_submodules('pandas._libs')
datas = collect_data_files('pandas')
我还添加了隐藏式导入 pkg_resources.py2_warn
因为这是我收到的一个错误
(base) C:\Users\...\test_folder>pyinstaller test.py -F --hidden-import pkg_resources.py2_warn
102 INFO: PyInstaller: 3.6
102 INFO: Python: 3.7.6 (conda)
106 INFO: Platform: Windows-10-10.0.18362-SP0
116 INFO: wrote C:\Users...\test_folder\test.spec
120 INFO: UPX is not available.
125 INFO: Extending PYTHONPATH with paths
注。-F
是相同的 --onefile
在 pyinstaller test.py -F --hidden-import pkg_resources.py2_warn
import pandas as pd
print('hello world')
input()
pyinstaller有这个问题,据报道 此处
hiddenimports = ['pandas._libs.tslibs.timedeltas',
'pandas._libs.tslibs.nattype',
'pandas._libs.tslibs.np_datetime',
'pandas._libs.skiplist']
如果不行的话,请尝试安装 pandas
使用 pip
.
pip install pandas
而不是通过 conda
据我所知,Pyinstaller的4.0版本还没有发布,我很惊讶。