gre*_*sgo 18 macos python-3.x pyenv macos-big-sur
我刚买了一台带有 M1 芯片的新 Macbook Air,我正在尝试通过 pyenv 安装 Python 3.8.3(或任何 3.x 版本)。我能够通过 Homebrew 安装 pyenv,但是当我尝试安装新的 python 版本时,出现如下错误。我相信这与新芯片和/或 Big Sur 操作系统有关。我已经尝试了这些链接中的说明,但错误消息是相同的:
https://github.com/pyenv/pyenv/issues/1643#issuecomment-655710632
https://dev.to/kojikanao/install-python-3-8-0-via-pyenv-on-bigsur-4oee
这是我在终端中输入的内容以及我得到的回报:
$ CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.8.3 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.3.tar.xz...
-> https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
Installing Python-3.8.3...
patching file Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst
patching file configure
Hunk #1 succeeded at 3398 (offset -28 lines).
patching file configure.ac
Hunk #1 succeeded at 498 (offset -12 lines).
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
BUILD FAILED (OS X 11.1 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/w3/wh28vlqs2txcyl67cjcd689h0000gn/T/python-build.20201217143449.26458
Results logged to /var/folders/w3/wh28vlqs2txcyl67cjcd689h0000gn/T/python-build.20201217143449.26458.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.
Run Code Online (Sandbox Code Playgroud)
小智 20
我遇到了同样的问题。正如我在最初的评论中提到的,Python 代码库中已经存在针对此的错误报告和补丁——尽管修复程序尚未发布。
同时,我采用的解决方案是在 Rosetta 2 下以“x86_64 模式”运行所有内容(包括 Homebrew)。要对任何给定命令执行此操作,请在命令前加上arch -x86_64. 或查看此内容以了解如何设置终端以在 Rosetta 下运行所有命令。
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Run Code Online (Sandbox Code Playgroud)
安装后,请确保您运行的是 x86_64 版本的brewfrom /usr/local/bin/brew。即你应该得到以下信息:
$ which brew
/usr/local/bin/brew
Run Code Online (Sandbox Code Playgroud)
如果您运行的是 arm64 版本,则/opt/homebrew/bin/brew需要修改系统路径以使其/usr/local/bin优先。FWIW,arm64 和 x86_64 Homebrew 安装可以和平共处。
arch -x86_64 brew install pyenv bzip2 zlib
Run Code Online (Sandbox Code Playgroud)
pyenv(根据OP 引用的此评论)安装所需版本的 PythonCFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
pyenv install --patch 3.8.3 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
Run Code Online (Sandbox Code Playgroud)
虽然我没有遵循上面的确切过程,但我相信它反映了所需的内容。我跳过了安装 XCode 命令行工具之类的步骤,这些步骤在别处都有详细记录。
如果你得到这样的错误
zipimport.ZipImportError: can't decompress data; zlib not available
Run Code Online (Sandbox Code Playgroud)
或警告,如
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
Run Code Online (Sandbox Code Playgroud)
这可能意味着 Homebrew 实际上没有正确安装这些库。做例如brew uninstall zlib && brew install zlib为我照顾那些。
小智 9
Homebrew 的 ARM 版本现在可以很好地安装 Pyenv。尽管并非所有版本都在 M1 上编译。3.7.9、3.9.2 编译得很好,但是,3.8(它尝试了 3.8.7 和 3.8.8)还没有正确的“arch”目标。