Skip to content

Commit

Permalink
compat: fix forced arch for helper-spawned python processes on macOS
Browse files Browse the repository at this point in the history
Extend the architecture setting in __wrap_python() on macOS to
handle arm64. Fixes helper-spawned python sub-processes failing
to start with "Bad CPU type in executable" when running under
arm64-only version of Python on Apple M1.
  • Loading branch information
rokm authored and bwoodsend committed Mar 18, 2021
1 parent 227eac1 commit a3b7414
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions PyInstaller/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,15 @@ def __wrap_python(args, kwargs):
# architecture as python executable.
# It is necessary to run binaries with 'arch' command.
if is_darwin:
mapping = {'32bit': '-i386', '64bit': '-x86_64'}
py_prefix = ['arch', mapping[architecture]]
if architecture == '64bit':
if machine == 'arm':
py_prefix = ['arch', '-arm64'] # Apple M1
else:
py_prefix = ['arch', '-x86_64'] # Intel
elif architecture == '32bit':
py_prefix = ['arch', '-i386']
else:
py_prefix = []
# Since OS X 10.11 the environment variable DYLD_LIBRARY_PATH is no
# more inherited by child processes, so we proactively propagate
# the current value using the `-e` option of the `arch` command.
Expand Down
2 changes: 2 additions & 0 deletions news/5640.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(macOS) Fix ``Bad CPU type in executable`` error in helper-spawned python
processes when running under ``arm64``-only flavor of Python on Apple M1.

0 comments on commit a3b7414

Please sign in to comment.