'How to run Python as X86 with Rosetta2 on ARM MacOS machine
I have a python app with downstream dependencies on dynamic libraries that are available as X86 only.
The app runs on a X86 MacOS machine, but on a ARM MacOS machine it fails with an ImportError.
I've run lipo -archs on the libraries and they are x86_64 only. I have Python running in a virtualenv and it is a universal binary x86_64 arm64. The intermediary object file built by the application when it installs is also a universal binary x86_64 arm64.
I suspect that Python is being run native as an ARM app, but because of the dependencies I need it run as an X86 app.
Is there a MacOS or Rosetta2 option or environmental setting that I can use that would force the X86 Python binary to be executed as opposed to the ARM binary?
Solution 1:[1]
Looks like the only way to do this is to install a X86 version of python.
I found a how to guide here - https://towardsdatascience.com/how-to-use-manage-multiple-python-versions-on-an-apple-silicon-m1-mac-d69ee6ed0250
but couldn't quite get the pyenv build part to work.
So in the Rosetta i386 terminal I brew86 installed python. This put a X86 version of python into /usr/local/bin/python3 from which I was able to create a X86 only virtualenv.
Broadly the steps are from the above link (minus the pyenv parts):
- Install Rosetta
- Create a Rosetta terminal
- Install X86 homebrew in the Rosetta terminal
- Create an alias for the X86 homebrew in
/usr/local/bin/brew - Use the X86 brew to install X86 python (ends up
/usr/local/bin/python3) - Create a virtualenv based on the X86 python path
- pip install
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
