On Jan 12, 2022, at 15:53, jack.jan...@cwi.nl wrote:
> Python runs just fine natively on M1 Macs. The python.org installer will 
> install a Universal2 binary (a single binary containing both the i386 and arm 
> architectures).
> 
> If you install through brew you get the architecture your brew has been 
> configured for.
> 
> But there _is_ a problem with native arm Python, and that is that not all 
> extension packages (think: from pypi) have M1 versions available yet. This is 
> especially true for packages that depend on external libraries (which may not 
> have been ported to M1 yet).
> 
> The way I handle this on my (M1) development machine is that I have both 
> versions of brew installed, which is easy because arm-brew installs into 
> /opt/homebrew by default and intel-brew installs into /usr/local.
> 
> If I open a Terminal window it has /opt/homebrew/bin before /usr/local/bin in 
> my $PATH, and the background is white.
> 
> If I open an iTerm window it runs in Rosetta intel emulation mode, it has 
> /usr/local/bin before /opt/homebrew/bin, and the background is a creamy 
> old-fashioned looking off-white color.
> 
> As long as I do builds in the window of the correct color, and the correct 
> tools I need for building have been installed in the correct directory 
> everything works fine.The white windows will use python3 for arm, the cream 
> windows will use python3 for intel.

That is one good solution.

For those using a universal2 (M1 arm64 and Intel-64 x86_64) build like those 
from the python.org installers or built from scratch with 
--with-universal-archs=universal2, 

./configure --enable-universalsdk --with-universal-archs=universal2 
--prefix=[...] or --enable-framework=[...] ...
make -j2 && make install

note that a separate python3{x}-intel64 Intel-only executable is installed 
along with the dual architecture python3{x} executable. In theory it is 
possible to select which architecture a multi-arch executable is to run under 
when there is more than one option by using the "arch" command, like here to 
force running in Intel emulation mode under Rosetta2 on an M1 Mac:

arch -x86_64 /path/to/python3{x}

But there is a big gotcha with that: if anything running under that non-default 
arch Python spins off another Python in a subprocess by using the value of 
sys.executable to find the running interpreter binary, the "arch -x86_64" is 
effectively lost and the interpreter in the subprocess will run in the default 
architecture. This happens, for instance, when running Python's own test suite: 
the top-level Python process running regrtest will be running in Intel 
emulation but tests running in subprocesses will still be running in the 
default arm64 arch, possibly giving errors or silently producing misleading 
results. Running the tests using python3{}-intel64 avoids that problem.

Also note that, as of today, we still don't officially support cross-building 
of single arch Pythons on macOS, that is, building an Intel-only Python on an 
M1 or vice-versa. If you need such a beast, what should work is building a 
universal2 version on either type of Mac and then using "lipo" on the 
executables and libraries as needed to produce a single arch set of files. Of 
course, that assumes that any third-party libraries needed for the build of 
Python have to also have been built with both archs.

--
  Ned Deily
  n...@python.org -- []

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
https://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG

Reply via email to