Installation of earlier versions of Python (prior to 3.8) fails on Mac with M1 Chip (ARM based Apple Silicon)
Asked Answered
S

8

28

I have Macbook with Apple M1 Chip in which I have to use Python 3.6.5 for my project. It comes with Python 2.7.16 and 3.8.2 preinstalled. I used brew to install Python which by default installed 3.9.1.

So, I tried this homebrew formula to install 3.6.5, but got following error:

checking for pthread_t... yes
checking size of pthread_t... 8
configure: error: Unexpected output of 'arch' on OSX

Do not report this issue to Homebrew/brew or Homebrew/core!

I tried pyenv install 3.6.5 , but it fails with similar error as above. Method explained here by ePi272314 to install python with git commit fails because it is no longer supported in homebrew.

When I try running Terminal with Rosetta 2 and install python 3.6.5, using above methods, I get the following, or some other compilation error:

Error: Cannot install in Homebrew under Rosetta 2 in ARM default prefix (/opt/homebrew)!

Finally, I downlaoded dmg file of Python 3.6.5 and installed it. It installed fine and it is visible as a python3 installation at /usr/local/bin/python3 but it cannot run.

kxxxr@Kxxxns-MBP bin % where python3
/opt/homebrew/bin/python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
/opt/homebrew/bin/python3
/usr/local/bin/python3
/usr/bin/python3
kxxxr@Kxxxns-MBP bin % /opt/homebrew/bin/python3 --version
Python 3.9.1
kxxxr@Kxxxns-MBP bin % /usr/local/bin/python3 --version
zsh: killed     /usr/local/bin/python3 --version
kxxxr@Kxxxns-MBP bin % 

Idle installed by Python dmg file cannot run either (I have admin rights).

Lastly came across this python bug report, which says bug is being fixed for Python 3.8, 3.9 and 3.10. Clearly, it looks like older version will not be supported on M1 chips officially.

My question is:

  1. Is there other way to work with Python 3.6.5 on Mac M1? Am I missing anything?
  2. If not, then please mention that. I will accept that as answer.

Thanks in advance.

Samathasamau answered 10/1, 2021 at 12:49 Comment(3)
I'd suggest running python, for now, under a Rosetta terminal. Many libs/etc require upstreams from the Homebrew major blockers list. FWIW I managed to install 3.7.9 (and up) via Homebrew under Rosetta 2.Armin
I did not check for 3.7.9, but 3.6.5 is not running under Rosetta 2 as well. I get the same zsh: killed as shown above. If it would have ran in Terminal running on Rosetta 2, than IDLE would would have ran properly at first place. I am saying this because 3.6.5 dmg is for x86 CPUs, hence IDLE by default would be running on Rosetta 2. But it also fails to launch as shown.Samathasamau
(Aside: I recommend against using Homebrew at all; the security model is really awful -- making /usr/local/bin user-writable means malware doesn't need to do any kind of privilege escalation to be able to put unsigned binaries in your PATH; there are many other reasons to use Nix, but its support for "daemon mode" where a separate nixbld user does all build tasks, and the /nix/store location everything is installed is read-only to all unprivileged users, is something I really appreciate).Belmonte
B
5

Nix installed under Rosetta 2 will do the trick. I didn't even have it installed before running the below -- note the message showing Nix downloading Python 3.6 when I requested it.

# yes, this really is a M1 Mac
charles@macbook-pro ~ % uname -a
Darwin macbook-pro.lan 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec  2 20:40:21 PST 2020; root:xnu-7195.60.75~1/RELEASE_ARM64_T8101 x86_64 i386 MacBookPro17,1 Darwin
charles@macbook-pro ~ % arch
arm64

# ...however, Rosetta was used to install an x86_64 Nix build
charles@macbook-pro ~ % file "$(realpath "$(command -v nix)")"
/nix/store/104sp9zrhmh3jycj32jcyl3f13mysdki-nix-2.3.9/bin/nix: Mach-O 64-bit executable x86_64

# ...and that x86_64 Nix build can install and run an x86_64 Python 3.6
charles@macbook-pro ~ % nix run nixpkgs.python36 -c python
[1 copied (53.7 MiB), 9.3 MiB DL]
Python 3.6.12 (default, Dec 18 2020, 15:32:50) 
[GCC 4.2.1 Compatible Clang 7.1.0 (tags/RELEASE_710/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

The above (for reproducibility purposes) was collected with nixpkgs referring to the channel https://nixos.org/channels/nixpkgs-20.09-darwin, and specifically to the instance sn5ycj9wkbdmyinvqyg9rn42sw71wqad-nixpkgs-20.09pre245572.f18fbc33930.

Belmonte answered 31/1, 2021 at 15:40 Comment(7)
...that said, nixpkgs 20.09's support for Python 3.6 is degrading a bit, since NixOS is currently using 3.8 as default -- they aren't caching binaries for popular packages like lxml or scipy anymore; if I needed to use Python 3.6 for a project, I'd probably think about pinning an older nixpkgs release for it, at least to the extent feasible from a security perspective.Belmonte
For beginners like me, follow this: 1. Install rosetta using "/usr/sbin/softwareupdate --install-rosetta" 2.Install nix "sh <(curl -L nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume" 3.Create a file .zprofile in home directory and add this line "source ~/.nix-profile/etc/profile.d/nix.sh" to be able to access nix using terminal. 4.Get a temp. shell of python (eg. 3.6) "nix-shell -p python36". 5.Use it to create virtual env. and use it anytime 6. Install packages in virtual env using pip. 7.Point python interpretor to that in virtual env for IDEs or wherever required.Samathasamau
@KundanKumar, ...it's possible to tell Nix to install your Python packages for you, so you don't need to use pip, but that's a pretty good place to start. :)Belmonte
@KundanKumar What about Python 3.5.4? When I run the "nix-shell -p python35" it just says undefined variable "python35". Any clue how I can run the python3.5 config?Girlhood
@VarunJoshi, I'd probably switch to an older nixpkgs from back when Python 3.5 was still supported -- last year's 20.09 might well be good enough. The old channels are still there, even if they aren't getting updates. See nix-channel to control the set of channels used to retrieve package definitions.Belmonte
I looks like nix removed python 3.6 support. nix-shell -p python36 should install and run a shell with python3.6 but looks like it is not available anymore.Evonevonne
@RobertMinasyan, right, but you can always enable an old channel from back when Python 3.6 was available. The binaries don't ever go away.Belmonte
S
15

Python 3.6 is not support on M1 might due to the fact that 3.6 will reach End Of Line (EOL) at the end of this year (2021).

I would suggest you to try at least Python 3.7 or higher on M1. Using pyenv, I've succeed install Python 3.7.10, 3.8.6 and 3.9.4 natively on macOS 11 (Apple Silicon). This article would help you though the process, if you're still looking for answer: https://squademy.medium.com/install-python-on-macos-11-m1-apple-silicon-using-pyenv-12e0729427a9

Suet answered 13/6, 2021 at 7:2 Comment(2)
I strongly support the suggestion of not installing Python 3.6 on M1 as it has reached EOL. The reason being even though it has been installed successfully, the attempts to install any packages, pandas, NumPy, SciPy will end up failing as well because newer versions of these don't work with older versions of Python. And older versions of these don't work on m1 chip.Demilitarize
I understand all these. But you can't do anything if project for your org requires 3.6.Samathasamau
B
5

Nix installed under Rosetta 2 will do the trick. I didn't even have it installed before running the below -- note the message showing Nix downloading Python 3.6 when I requested it.

# yes, this really is a M1 Mac
charles@macbook-pro ~ % uname -a
Darwin macbook-pro.lan 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec  2 20:40:21 PST 2020; root:xnu-7195.60.75~1/RELEASE_ARM64_T8101 x86_64 i386 MacBookPro17,1 Darwin
charles@macbook-pro ~ % arch
arm64

# ...however, Rosetta was used to install an x86_64 Nix build
charles@macbook-pro ~ % file "$(realpath "$(command -v nix)")"
/nix/store/104sp9zrhmh3jycj32jcyl3f13mysdki-nix-2.3.9/bin/nix: Mach-O 64-bit executable x86_64

# ...and that x86_64 Nix build can install and run an x86_64 Python 3.6
charles@macbook-pro ~ % nix run nixpkgs.python36 -c python
[1 copied (53.7 MiB), 9.3 MiB DL]
Python 3.6.12 (default, Dec 18 2020, 15:32:50) 
[GCC 4.2.1 Compatible Clang 7.1.0 (tags/RELEASE_710/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

The above (for reproducibility purposes) was collected with nixpkgs referring to the channel https://nixos.org/channels/nixpkgs-20.09-darwin, and specifically to the instance sn5ycj9wkbdmyinvqyg9rn42sw71wqad-nixpkgs-20.09pre245572.f18fbc33930.

Belmonte answered 31/1, 2021 at 15:40 Comment(7)
...that said, nixpkgs 20.09's support for Python 3.6 is degrading a bit, since NixOS is currently using 3.8 as default -- they aren't caching binaries for popular packages like lxml or scipy anymore; if I needed to use Python 3.6 for a project, I'd probably think about pinning an older nixpkgs release for it, at least to the extent feasible from a security perspective.Belmonte
For beginners like me, follow this: 1. Install rosetta using "/usr/sbin/softwareupdate --install-rosetta" 2.Install nix "sh <(curl -L nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume" 3.Create a file .zprofile in home directory and add this line "source ~/.nix-profile/etc/profile.d/nix.sh" to be able to access nix using terminal. 4.Get a temp. shell of python (eg. 3.6) "nix-shell -p python36". 5.Use it to create virtual env. and use it anytime 6. Install packages in virtual env using pip. 7.Point python interpretor to that in virtual env for IDEs or wherever required.Samathasamau
@KundanKumar, ...it's possible to tell Nix to install your Python packages for you, so you don't need to use pip, but that's a pretty good place to start. :)Belmonte
@KundanKumar What about Python 3.5.4? When I run the "nix-shell -p python35" it just says undefined variable "python35". Any clue how I can run the python3.5 config?Girlhood
@VarunJoshi, I'd probably switch to an older nixpkgs from back when Python 3.5 was still supported -- last year's 20.09 might well be good enough. The old channels are still there, even if they aren't getting updates. See nix-channel to control the set of channels used to retrieve package definitions.Belmonte
I looks like nix removed python 3.6 support. nix-shell -p python36 should install and run a shell with python3.6 but looks like it is not available anymore.Evonevonne
@RobertMinasyan, right, but you can always enable an old channel from back when Python 3.6 was available. The binaries don't ever go away.Belmonte
S
3

Using answer of @Charles Duffy you can make older versions run on M1s. However Python versions before 3.8 will NOT be officially supported on M1 because they were not in bug-fix phase when M1 chips were released. It is stated clearly here as:

">Are there plans to backport PR 22855 to any branches older than 3.9?

The plan is to also support 3.8 on Big Sur and Apple Silicon as 3.8 is still in bugfix mode. There are no plans to backport support to 3.7 and 3.6 which are in the security-fix-only phase of their release cycles."

in this python bug tracker.

So I don't think there is any way to get them working on M1 unless someone tweaks python on their own.

Samathasamau answered 31/1, 2021 at 15:34 Comment(1)
The OP didn't ask it for it to be M1-native. Sure, it'll require a patch to get a native build, but if they're happy with Rosetta, no patch is needed.Belmonte
L
2

I am a bit late compared to the other answers, but I was struggling with this as well. I found a different solution.

I wanted to use conda to make a python3.6 environment, but this kept failing on my Mac with a M1 chip

conda create --name myenv python=3.6
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
 - python=3.6

best I could do was python 3.8, even when using --channel conda-forge.

The solution was downloading a different version of conda miniconda3. instead of selecting the "Miniconda3 macOS Apple M1 64-bit pkg" I chose the "Miniconda3 macOS Intel x86 64-bit pkg" (intel version). Now creating a python 3.6 conda environment runs smoothly. This way you can still run old code in the conda environment, without messing with the mac python version.

Hope this helps others as well, as the above solutions did not seem to work.

Limpkin answered 14/9, 2022 at 9:16 Comment(0)
D
1

I was able to install 3.8 from source:

./configure --enable-framework=/Users/MyUName/lib/Frameworks
make && make install

I tried 3.7 and it died during make:

cd Mac && /Applications/Xcode.app/Contents/Developer/usr/bin/make pythonw
gcc  -DPYTHONFRAMEWORK='"Python"' -o pythonw \
        ./Tools/pythonw.c -I.. -I./../Include \
        ../Python.framework/Versions/3.7/Python
./Tools/pythonw.c:125:9: error: "Unknown CPU"
#       error "Unknown CPU"
        ^

I tried 3.6 and it died during config:

checking for g++... no
configure:

  By default, distutils will build C++ extension modules with "g++".
  If this is not intended, then set CXX on the configure command line.

so I tried adding CXX=$(xcode-select -p)/usr/bin/g+ and it didn't get much further:

checking for the platform triplet based on compiler characteristics... darwin
configure: error: internal configure error for the platform triplet, please file a bug report

Conda doesn't even support 3.6 and 3.7 for M1.

Detrimental answered 25/3, 2022 at 18:5 Comment(0)
S
0

I am agree with what @Fini has suggested to use x86-64 miniconda3. This can install python 3.6.13, I needed 3.6.15 but I should be fine with 3.6.13. I can install now all packages.

Before I used pyenv to install python and work in it's virtual environment ecosystem. I had issues with pandas package installation, because it needed numpy. I have locked my microservices to use python 3.6.15, so pip install numpy couldn't install [email protected]. Now I just managed to do same environment thing with conda, could install pandas, numpy was installed by pandas as it was dependency of it.

Hope this helps to others!

Sogdian answered 7/7, 2023 at 4:26 Comment(0)
R
0

Try arch -x86_64 pyenv install 3.6.5 on Apple Silicon

Reverential answered 22/12, 2023 at 4:30 Comment(0)
J
-1

Although it's EOL, you can install the final version 3.6.15 on a Mac M1 using pyenv.

Joniejonina answered 17/1, 2022 at 15:9 Comment(2)
Does not help. Please provide more info on the process/how-to fix the issue as mentioned by OP.Looming
@Joniejonina can you explain how you accomplished this with pyenv?Lollapalooza

© 2022 - 2025 — McMap. All rights reserved.