在Mac M1上安装python 3.6.*



我正在尝试运行一个需要python<3.7.我目前使用的是python 3.9,需要使用多个版本的python。

我已经安装了pyenv-virtualenvpyenv,并成功安装了python 3.7.13。然而,当我尝试安装3.6.*时,我得到的是:

$ pyenv install 3.6.13
python-build: use openssl@1.1 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.

有办法解决这个问题吗?我看了看,似乎Mac M1不允许安装3.6。*

从GitHub问题复制。


我使用以下设置在运行Monterey的Apple M1 MacBook Pro上成功安装了Python3.6。这里可能有一些东西可以删除/提炼。。。但它对我有用!

#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 PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA=openssl@1.0
# 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)

注意,构建成功,但会发出以下警告

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

运行pyenv versions表明系统可以正常使用3.6.15

在花了几天时间关注网络上的每一个教程,但都没有成功,多亏了一位同事,我发现一个简单的brew install pyenvpyenv install 3.6现在可以在M1上工作。

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

没有罗塞塔,没有x86技巧,只有普通的ARM,也许在此期间发生了什么变化?

注意:当使用尚未在ARM架构上运行的包时,可能会遇到问题,比如PyTorch(仅限实验支持(

编辑:在评论中,据报道pyenv install 3.6.15与Mac安装了一个带有Ventura 13.4 OSX版本的M2芯片组,但早期的Python版本无法安装。

添加到dontryrun的答案中。

您可能会得到如下错误。

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?

这是因为您已经安装了另一个openssl版本,该版本更高达1.0,可能是3。您可以更新以下突出显示的命令。

#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 openssl@1.1 here and others as well ----------+
#                                                                        ↓
export CPPFLAGS="-I$(brew86 --prefix libffi)/include -I$(brew86 --prefix openssl@1.1)/include -I$(brew86 --prefix readline)/lib"
export CFLAGS="-I$(brew86 --prefix openssl@1.1)/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@1.1)/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 PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA=openssl@1.1
# 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)

相关内容

  • 没有找到相关文章

最新更新