用PyInstaller错误,无法用Pandas创建一个.exe文件。

问题描述 投票:0回答:1

我使用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

python-3.x pandas pyinstaller
1个回答
2
投票

钩子-pandas.py

添加 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 是相同的 --onefilepyinstaller test.py -F --hidden-import pkg_resources.py2_warn

测试.py

import pandas as pd
print('hello world')
input()

1
投票

pyinstaller有这个问题,据报道 此处

  1. 按照线程中的建议设置你的隐藏导入。
hiddenimports = ['pandas._libs.tslibs.timedeltas',
'pandas._libs.tslibs.nattype',
'pandas._libs.tslibs.np_datetime',
'pandas._libs.skiplist']
  1. 如果不行的话,请尝试安装 pandas 使用 pip.

    pip install pandas而不是通过 conda

据我所知,Pyinstaller的4.0版本还没有发布,我很惊讶。

© www.soinside.com 2019 - 2024. All rights reserved.