macOS: add support for macOS 11 and Apple M1 Silicon (arm64) by rokm · Pull Request #5581 · pyinstaller/pyinstaller (original) (raw)

This PR is now rebased on top of develop and revised according to feedback and lessons learned so far. Most notably:

This should enable creation of frozen applications for all possible arch combinations; single-arch with single-arch python, universal2 with universal2 python, and single-arch with universal2 python.

For example, freezing a "Hello world" script with universal2 python on x86_64 macOS:

 $ pyinstaller hello.py
 $ lipo -archs dist/hello/hello 
 x86_64
$ lipo -archs dist/hello/Python 
x86_64

Building universal2 version:

$ pyinstaller hello.py --distpath dist-universal2 --target-arch universal2
$ lipo -archs dist-universal2/hello/hello 
x86_64 arm64
$ lipo -archs dist-universal2/hello/Python 
x86_64 arm64

Building arm64-only version ("cross-compiling"):

$ pyinstaller hello.py --distpath dist-arm64 --target-arch arm64
$ lipo -archs dist-arm64/hello/hello 
arm64
$ lipo -archs dist-arm64/hello/Python 
arm64

Trying to build a universal2 or arm64 version of a progam that imports psutil, however, will fail due to psutil providing single-arch wheel:

$ pyinstaller program_psutil.py --distpath dist-universal2 --target-arch universal2
...
AssertionError: [...]/venv/lib/python3.9/site-packages/psutil/_psutil_osx.cpython-39-darwin.so is not a fat binary!
$ pyinstaller program_psutil.py --distpath dist-arm64 --target-arch arm64
...
AssertionError: [...]/venv/lib/python3.9/site-packages/psutil/_psutil_osx.cpython-39-darwin.so is incompatible with target arch arm64 (has arch: x86_64)!