xcode MacOS上的pyenv zlib错误:

pbpqsu0x  于 2023-03-24  发布在  Mac
关注(0)|答案(9)|浏览(195)

我的目标

我正在尝试使用pyenv在我的MBP上并排安装Python 2.7.5和3.6.5。

pyenv安装

How can I use Homebrew to install both Python 2 and 3 on Mac?之后,我尝试了:

$ pyenv install 3.6.5

其错误在于:

python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.5.tar.xz...
-> https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
Installing Python-3.6.5...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.13.4 using python-build 20160602)

Inspect or clean up the working tree at /var/folders/d0/t8d3jjp161g2dyrd4k67ypc80000gn/T/python-build.20180426091253.34709
Results logged to /var/folders/d0/t8d3jjp161g2dyrd4k67ypc80000gn/T/python-build.20180426091253.34709.log

Last 10 log lines:
  File "/private/var/folders/d0/t8d3jjp161g2dyrd4k67ypc80000gn/T/python-build.20180426091253.34709/Python-3.6.5/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/private/var/folders/d0/t8d3jjp161g2dyrd4k67ypc80000gn/T/python-build.20180426091253.34709/Python-3.6.5/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/d0/t8d3jjp161g2dyrd4k67ypc80000gn/T/python-build.20180426091253.34709/Python-3.6.5/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/d0/t8d3jjp161g2dyrd4k67ypc80000gn/T/python-build.20180426091253.34709/Python-3.6.5/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1

我尝试了什么

  • 安装zlib:brew install zlib

∮我的问题∮
如何在MBP上使用pyenv安装多个Python环境?

fgw7neuy

fgw7neuy1#

在莫哈韦上,安装Xcode命令行工具后,必须运行以下命令:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
dauxcl2d

dauxcl2d2#

brew install zlib
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
pyenv install 3.7.2

Samsin的回答对我不起作用。我没有Packages目录

vxqlmq5t

vxqlmq5t3#

在MacOS 11.1(Big Sur)上,我最终需要:

brew install bzip2
export LDFLAGS="-L $(xcrun --show-sdk-path)/usr/lib -L brew --prefix bzip2/lib"
export CFLAGS="-L $(xcrun --show-sdk-path)/usr/include -L brew --prefix bzip2/include"
pyenv install 3.9.0

我在./bash_profile中添加了导出命令,这样下次我需要安装更多版本时就可以使用pyenv了。
密切关注:https://github.com/pyenv/pyenv/issues/1643跟踪这个问题,希望这将在pyenv中得到修复。

ndasle7k

ndasle7k4#

我尝试了这里所有的解决方案,但没有成功。
这是我在MacOs 11.2.1(Big Sur)上的工作:

export MACOSX_DEPLOYMENT_TARGET=11.0
brew install pyenv bzip2 zlib xz openssl@1.1

## 3.6.8
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.6.8 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

## 3.6.12
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.6.12 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

## 3.7.9
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 3.7.9

解取自this gist

uhry853o

uhry853o5#

pyenv wiki有一个专门针对常见构建问题的页面。对于missing zlib错误,有一些可能的解决方案。
我有相同的ZipImportError,但使用以下命令安装成功:

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.6.5
bvn4nwqk

bvn4nwqk6#

为了得到带有tkinter的Python 3.8.6,我在Vincent Gerris的答案和this blog post的基础上进行了构建,并在

brew install bzip2
export LDFLAGS="-L $(xcrun --show-sdk-path)/usr/lib -L brew --prefix bzip2/lib"
export CFLAGS="-L $(xcrun --show-sdk-path)/usr/include -L brew --prefix bzip2/include"
export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6' --enable-framework"
pyenv install 3.8.6
llycmphe

llycmphe7#

solution by @mathsyouth对我很有效,但我必须在命令之前添加arch -x86_64

wwwo4jvm

wwwo4jvm8#

确保你最近打开过XCode,并在第一次打开的过程中授予了权限。这为我解决了这个问题。这个想法来自:
https://github.com/pyenv/pyenv/issues/2112#issuecomment-1265874025

xggvc2p6

xggvc2p69#

以下是我在macOS Big Sur(11.6.1)上的工作原理:

brew update
brew install bzip2
echo 'export PATH="/usr/local/opt/bzip2/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
pyenv install 3.8.6

相关问题