pyinstaller无法生成可执行文件

2024-03-28 19:32:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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,所以我想这可能是苹果硅的问题。我试着用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 )

Tags: pydevinfowebfalsebinanalysisscraper