pyinstaller 无法构建可执行文件

问题描述

我正在尝试使用 pyinstaller --onefile web_scraper.py 使用 pyinstaller 构建可执行文件,但我不断收到此错误

29 INFO: PyInstaller: 4.1
29 INFO: Python: 3.9.2
37 INFO: Platform: macOS-11.2.3-arm64-arm-64bit
37 INFO: wrote /Users/jacobarmiger/dev/comic-list-web-scraper/web_scraper.spec
38 INFO: UPX is not available.
39 INFO: Extending PYTHONPATH with paths
['/Users/jacobarmiger/dev/comic-list-web-scraper','/Users/jacobarmiger/dev/comic-list-web-scraper']
42 INFO: checking Analysis
42 INFO: Building Analysis because Analysis-00.toc is non existent
42 INFO: Initializing module dependency graph...
42 INFO: Caching module graph hooks...
45 INFO: Analyzing base_library.zip ...
arch: posix_spawnp: /opt/homebrew/opt/python@3.9/bin/python3.9: Bad cpu type in executable
arch: posix_spawnp: /opt/homebrew/opt/python@3.9/bin/python3.9: Bad cpu type in executable
998 INFO: Processing pre-find module path hook distutils from '/opt/homebrew/lib/python3.9/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
998 INFO: distutils: retargeting to non-venv dir '/opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9'
2093 INFO: Caching module dependency graph...
2125 INFO: running Analysis Analysis-00.toc
2128 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /opt/homebrew/opt/python@3.9/bin/../Frameworks/Python.framework/Versions/3.9/bin/python3.9)
2129 ERROR: Can not find path /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (needed by /opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/Python)
2129 ERROR: Can not find path /usr/lib/libSystem.B.dylib (needed by /opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/Python)
2129 INFO: Analyzing /Users/jacobarmiger/dev/comic-list-web-scraper/web_scraper.py
2174 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from '/opt/homebrew/lib/python3.9/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-urllib3.packages.six.moves.py'.
arch: posix_spawnp: /opt/homebrew/opt/python@3.9/bin/python3.9: Bad cpu type in executable
pre-safe-import-module hook Failed,needs fixing.

我看到那里的 cpu 很差,所以我认为这可能是 Apple 芯片的问题。我试过用 Rosetta 和其他一些解决方案运行我的终端,但没有任何效果。这是 arm64 的问题吗?这是我的项目:https://github.com/jacob-armiger/comic-list-web-scraper。如果您想看看它是否可以那样工作,那么尝试在您自己的机器上执行应该很容易。如果有帮助,这里还有我的 .spec 文件

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['web_scraper.py'],pathex=['/Users/jacobarmiger/dev/comic-list-web-scraper'],binaries=[],datas=[],hiddenimports=[],hookspath=[],runtime_hooks=[],excludes=[],win_no_prefer_redirects=False,win_private_assemblies=False,cipher=block_cipher,noarchive=False)
pyz = PYZ(a.pure,a.zipped_data,cipher=block_cipher)
exe = EXE(pyz,a.scripts,a.binaries,a.zipfiles,a.datas,[],name='web_scraper',debug=False,bootloader_ignore_signals=False,strip=False,upx=True,upx_exclude=[],runtime_tmpdir=None,console=True )

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)