Contents

Limited versions in python are supported in Pyenv on M1 Mac

Environment

  • MacOS Monterey 12.0, M1 Apple silicon
  • Python 3.7.9, 3.8.6, 3.9.1, 3.9.7, 3.10.0
  • pyenv 2.2.0
  • Homebrew 3.3.1

Problem

I got new M1 Macbook Pro 14 inch, a device should be with literally the coolest spec in my life. However, it’s not necessarily smooth work to setup environment.

When I tried to install python 3.9.7 or 3.8.6 via pyenv.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ pyenv install 3.8.6
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.6.tar.xz...
-> https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tar.xz
Installing Python-3.8.6...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 12.0 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/72/czdc_d1n5ds8rww6b_f_q2tw0000gn/T/python-build.20211028225403.61470
Results logged to /var/folders/72/czdc_d1n5ds8rww6b_f_q2tw0000gn/T/python-build.20211028225403.61470.log

Last 10 log lines:
checking size of _Bool... 1
checking size of off_t... 8
checking whether to enable large file support... no
checking size of time_t... 8
checking for pthread_t... yes
checking size of pthread_t... 8
checking size of pthread_key_t... 8
checking whether pthread_key_t is compatible with int... no
configure: error: Unexpected output of 'arch' on OSX
make: *** No targets specified and no makefile found.  Stop.

Solution (workaround)

It seems because CPython in pyenv supports i386-based chip formerly and only few versions in python installable in pyenv are compatible with M1 Apple silicon with arm64.

In the past discussion in Python build fails on M1 Apple Silicon with arm64 homebrew, python 3.7.9 and 3.9.1 worked.

Also, python 3.10.0 works as well.

1
2
3
4
5
6
7
8
9
$ pyenv install 3.7.9
$ pyenv install 3.9.1
$ pyenv install 3.10.0

$ pyenv versions
* system (set by /Users/tato/.pyenv/version)
  3.10.0
  3.7.9
  3.9.1

For switching python version,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$ pyenv local 3.10.0

$ pyenv versions
  system
* 3.10.0 (set by /Users/tato/repo/github/tatoflam/concurrent-api-client/.python-version)
  3.7.9
  3.9.1

$ pyenv rehash
$ python -V
Python 3.10.0

$ which python
/Users/tato/.pyenv/shims/python

When I could not switch the python interpreter even if pyenv rehash works, I added --path parameter to pyenv init in .bash_profile

.bash_profile

1
2
3
4
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
~                             

References