machawk1 / wail

:whale2: Web Archiving Integration Layer: One-Click User Instigated Preservation
https://matkelly.com/wail
MIT License
345 stars 32 forks source link

Update to package with pyinstaller 4.4 #522

Closed machawk1 closed 2 years ago

machawk1 commented 2 years ago

Includes support for packaging for Apple Silicon (#494 relied on a pre-release) among other fixes.

machawk1 commented 2 years ago

There appears to be an issue with the requests library, specifically its usage of urllib3, with pyinstaller 4.4.

Reporting the bug to pyinstaller is a process of verification with various guides as a pre-requisite, so I will just report a fundamental issue here for further investigation.

import requests
print('hello')
% pyinstaller --log-level DEBUG pyinstaller-requests-test.py
24 INFO: PyInstaller: 4.4
24 INFO: Python: 3.9.6
30 INFO: Platform: macOS-11.4-arm64-arm-64bit
30 INFO: wrote /private/tmp/pyinstaller-requests-test.spec
31 DEBUG: Testing for UPX ...
33 INFO: UPX is not available.
33 DEBUG: script: /private/tmp/pyinstaller-requests-test.py
33 INFO: Extending PYTHONPATH with paths
['/private/tmp', '/private/tmp']
36 INFO: checking Analysis
37 INFO: Building because /opt/homebrew/lib/python3.9/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgutil.py changed
37 INFO: Initializing module dependency graph...
38 INFO: Caching module graph hooks...
41 INFO: Analyzing base_library.zip ...
41 DEBUG: Collecting submodules for collections
arch: posix_spawnp: /opt/homebrew/opt/python@3.9/bin/python3.9: Bad CPU type in executable
44 DEBUG: collect_submodules - Found submodules: {'collections'}
44 DEBUG: Collecting submodules for encodings
arch: posix_spawnp: /opt/homebrew/opt/python@3.9/bin/python3.9: Bad CPU type in executable
46 DEBUG: collect_submodules - Found submodules: {'encodings'}
971 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'.
971 INFO: distutils: retargeting to non-venv dir '/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9'
2078 INFO: Caching module dependency graph...
2107 DEBUG: Adding python files to base_library.zip
2119 INFO: running Analysis Analysis-00.toc
2119 DEBUG: Analyzing /opt/homebrew/opt/python@3.9/bin/../Frameworks/Python.framework/Versions/3.9/bin/python3.9
2120 DEBUG: Adding Python dependency of python3.9 from /opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/Python
2120 DEBUG: Analyzing /opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/Python
2121 INFO: Analyzing /private/tmp/pyinstaller-requests-test.py
2168 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.

...creates no binary in dist on an M1 Mac.

# import requests
print('hello')

...places a binary in ./dist but even running that is problematic:

% ./dist/pyinstaller-requests-test
Python path configuration:
  PYTHONHOME = '/var/folders/s2/dqb5xbtj2x90kksrxdg5lhym0000gp/T/_MEINJxzze'
  PYTHONPATH = (not set)
  program name = '/private/tmp/dist/pyinstaller-requests-test'
  isolated = 0
  environment = 0
  user site = 0
  import site = 0
  sys._base_executable = '/private/tmp/dist/pyinstaller-requests-test'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = '/private/tmp/dist/pyinstaller-requests-test'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    '/var/folders/s2/dqb5xbtj2x90kksrxdg5lhym0000gp/T/_MEINJxzze/base_library.zip',
    '/var/folders/s2/dqb5xbtj2x90kksrxdg5lhym0000gp/T/_MEINJxzze/lib-dynload',
    '/var/folders/s2/dqb5xbtj2x90kksrxdg5lhym0000gp/T/_MEINJxzze',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
LookupError: unknown encoding: utf-8

Current thread 0x0000000100a03d40 (most recent call first):
<no Python frame>
machawk1 commented 2 years ago

Not reproducible on an i5 Mac w/ macOS 10.14.6. It is likely an issue of requests on the new architecture.