Install python 3.6.* on Mac M1
Asked Answered
R

4

15

I'm trying to run an old app that requires python < 3.7. I'm currently using python 3.9 and need to use multiple versions of python.

I've installed pyenv-virtualenv and pyenv and successfully installed python 3.7.13. However, when I try to install 3.6.*, I get this:

$ pyenv install 3.6.13
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.13.tar.xz...
-> https://www.python.org/ftp/python/3.6.13/Python-3.6.13.tar.xz
Installing Python-3.6.13...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 12.3.1 using python-build 2.2.5-11-gf0f2cdd1)

Inspect or clean up the working tree at /var/folders/r5/xz73mp557w30h289rr6trb800000gp/T/python-build.20220413143259.33773
Results logged to /var/folders/r5/xz73mp557w30h289rr6trb800000gp/T/python-build.20220413143259.33773.log

Last 10 log lines:
checking for --with-cxx-main=<compiler>... no
checking for clang++... no
configure:

  By default, distutils will build C++ extension modules with "clang++".
  If this is not intended, then set CXX on the configure command line.
  
checking for the platform triplet based on compiler characteristics... darwin
configure: error: internal configure error for the platform triplet, please file a bug report
make: *** No targets specified and no makefile found.  Stop.

Is there a way to solve this? I've looked and it seems like Mac M1 doesn't allow installing 3.6.*

Reredos answered 13/4, 2022 at 18:37 Comment(4)
I would probably spend more time seeing what actually needs to be upgraded to make it run with a new version of Python.Gardell
are you going to use python for arm, or x86 through rosetta?Meissen
I'm going to use python for ARMReredos
ok, the easiest experience I've had installing python for arm was by installing miniconda with homebrew, and then using conda environments to create the python3.6 environmentMeissen
L
29

Copying from a GitHub issue.


I successfully installed Python 3.6 on an Apple M1 MacBook Pro running Monterey using the following setup. There is probably some things in here that can be removed/refined... but it worked for me!

#Install Rosetta
/usr/sbin/softwareupdate --install-rosetta --agree-to-license

# Install x86_64 brew
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

# Set up x86_64 homebrew and pyenv and temporarily set aliases
alias brew86="arch -x86_64 /usr/local/bin/brew"
alias pyenv86="arch -x86_64 pyenv"

# Install required packages and flags for building this particular python version through emulation
brew86 install pyenv gcc libffi gettext
export CPPFLAGS="-I$(brew86 --prefix libffi)/include -I$(brew86 --prefix openssl)/include -I$(brew86 --prefix readline)/lib"
export CFLAGS="-I$(brew86 --prefix openssl)/include -I$(brew86 --prefix bzip2)/include -I$(brew86 --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include -Wno-implicit-function-declaration" 
export LDFLAGS="-L$(brew86 --prefix openssl)/lib -L$(brew86 --prefix readline)/lib -L$(brew86 --prefix zlib)/lib -L$(brew86 --prefix bzip2)/lib -L$(brew86 --prefix gettext)/lib -L$(brew86 --prefix libffi)/lib"

# Providing an incorrect openssl version forces a proper openssl version to be downloaded and linked during the build
export [email protected]

# Install Python 3.6
pyenv86 install --patch 3.6.15 <<(curl -sSL https://raw.githubusercontent.com/pyenv/pyenv/master/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0008-bpo-45405-Prevent-internal-configure-error-when-runn.patch\?full_index\=1)

Note, the build succeeds but gives the following warning

WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?

running pyenv versions shows that 3.6.15 can be used normally by the system

Liqueur answered 21/4, 2022 at 16:39 Comment(4)
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib? This is the error I get, so I assume that a proper openssl version is not forced. Has anyone else encountered this while following the above steps? If so, how did you overcome it?Interbreed
This worked to me, but have to mark the terminal to 'open with Rosetta'Frig
@Interbreed Could you find a solution for the ssl issue?Spermous
@OmkarKulkarni yes - on the line: brew86 install pyenv gcc libffi gettext, add openssl (but only do this before the last line in the instructions (pyenv86 install --patch...) If you already did that, uninstall everything and start over, but with the openssl added to the brew86 install cmdInterbreed
V
10

After spending days following each and every tutorial on the Web without success, I found out thanks to a co-worker that a plain brew install pyenv followed by pyenv install 3.6 now works on M1.

$ sw_vers
ProductName:    macOS
ProductVersion: 12.6.2
BuildVersion:   21G320

No rosetta, no x86 tricks, just plain ARM, maybe something has changed in the meantime?

Caveat: you could run into problems when using packages that do not yet run on ARM architecture natively, like PyTorch (experimental support only)

EDIT: in the comments it's reported that pyenv install 3.6.15 works with Mac mounting an M2 chipset with Ventura 13.4 OSX version, earlier Python versions couldn't be installed, though.

Victorvictoria answered 6/3, 2023 at 13:7 Comment(5)
Well you could run into problems when using packages that do not yet run on ARM architecture natively, like PyTorch (experimental support only)Perplexity
I haven't encountered any issues yet but I guess you are rightVictorvictoria
I have added your remark as "caveat" at the end of the answer, so people are aware of potential issuesVictorvictoria
I have a new M2 with Ventura 13.4 and need to run a 3.6 Python to maintain an older couple of projects that can't have their Python rev updated at this time. After suffering many trials and tribulations using Rosetta, x86 Brew, MacPorts, compiler flags out the ying yang.. I stumbled upon this and it works!! One note though.. only worked for 3.6.15, not for any earlier 3.6 versions. So for me the command was: 'pyenv install 3.6.15'. Funny that this seems relatively unknown at this time, isn't it?Hemoglobin
@PaulBrackin thanks for sharing, I was in the same exact situation with M1 and a legacy project, I tried all you suggest too and was surprised the simplest approach worked. I have updated the answer with your extra info, thanks again.Victorvictoria
S
1

Adding to the answer of dontirun.

You might get the error as below.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/kullya/.pyenv/versions/3.6.15/lib/python3.6/ssl.py", line 101, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

This is because you have another openssl version already installed that is higher to 1.0, possibly 3. You can update the commands as highlighted below.

#Install Rosetta
/usr/sbin/softwareupdate --install-rosetta --agree-to-license

# Install x86_64 brew
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

# Set up x86_64 homebrew and pyenv and temporarily set aliases
alias brew86="arch -x86_64 /usr/local/bin/brew"
alias pyenv86="arch -x86_64 pyenv"

# Install required packages and flags for building this particular python version through emulation
brew86 install pyenv gcc libffi gettext

# -------------- change to [email protected] here and others as well ----------+
#                                                                        ↓
export CPPFLAGS="-I$(brew86 --prefix libffi)/include -I$(brew86 --prefix [email protected])/include -I$(brew86 --prefix readline)/lib"
export CFLAGS="-I$(brew86 --prefix [email protected])/include -I$(brew86 --prefix bzip2)/include -I$(brew86 --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include -Wno-implicit-function-declaration" 
export LDFLAGS="-L$(brew86 --prefix [email protected])/lib -L$(brew86 --prefix readline)/lib -L$(brew86 --prefix zlib)/lib -L$(brew86 --prefix bzip2)/lib -L$(brew86 --prefix gettext)/lib -L$(brew86 --prefix libffi)/lib"

# Providing an incorrect openssl version forces a proper openssl version to be downloaded and linked during the build
export [email protected]

# Install Python 3.6
pyenv86 install --patch 3.6.15 <<(curl -sSL https://raw.githubusercontent.com/pyenv/pyenv/master/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0008-bpo-45405-Prevent-internal-configure-error-when-runn.patch\?full_index\=1)
Spermous answered 3/2, 2023 at 2:45 Comment(3)
OS X 12.6.2 using python-build 20180424, failing at openSSL even with these instructionsVictorvictoria
@AlessandroS. Maybe you should use brew86 uninstall openssl first, then run all the commands in this post, not only the last two commands.Foulup
I have added as a separate answer that now everything works out of the box on M1, something must have changed since nobody mentions that!Victorvictoria
A
0

Using pyenv 2.25 from homebrew on Apple Silicon with macOS 12.3.1 (21E258) / Xcode 13.3 (13E113).

For 3.6.15 you'll need this merged but unreleased pyenv patch: https://raw.githubusercontent.com/pyenv/pyenv/master/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0008-bpo-45405-Prevent-internal-configure-error-when-runn.patch in /opt/homebrew/Cellar/pyenv/2.2.5/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/

For 3.7.12 you'll need this merged but unreleased pyenv patch: https://raw.githubusercontent.com/pyenv/pyenv/master/plugins/python-build/share/python-build/patches/3.7.12/Python-3.7.12/0004-bpo-45405-Prevent-internal-configure-error-when-runn.patch in /opt/homebrew/Cellar/pyenv/2.2.5/plugins/python-build/share/python-build/patches/3.7.12/Python-3.7.12/

3.7.13 is unreleased and currently missing merged 3.7.12 patch.

https://github.com/pyenv/pyenv/tree/fb97a9c2bd8c0e7b582d4b525cd348cc2ed5359a/plugins/python-build/share/python-build/patches/3.7.13/Python-3.7.13

No issues with 3.8.13 build.

pyenv versions
* system (set by /Users/admin/.pyenv/version)
 3.6.15
 3.7.12
 3.8.13
Aultman answered 25/1, 2024 at 8:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.