gpt4 book ai didi

python-3.x - 无法使用 PyInstaller 错误创建 .exe 文件

转载 作者:行者123 更新时间:2023-12-04 13:14:59 25 4
gpt4 key购买 nike

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

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')

Anaconda 提示符

我还添加了隐藏导入 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

注意:-Fpyinstaller test.py -F --hidden-import pkg_resources.py2_warn中的--onefile相同

测试.py

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

关于python-3.x - 无法使用 PyInstaller 错误创建 .exe 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61396071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com