19

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.

4

4 回答 4

7

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

于 2021-06-13T07:02:04.207 回答
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.

于 2021-01-31T15:40:29.760 回答
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.

于 2021-01-31T15:34:40.557 回答
0

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

于 2022-01-17T15:09:58.880 回答