xcode MacOS 上的 pyenv zlib 错误:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50036091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:37:44  来源:igfitidea点击:

pyenv zlib error on MacOS:

xcodemacoszlibpyenv

提问by Adam Matan

My goal

我的目标

I am trying to install Python 2.7.5 and 3.6.5 side-by-side on my MBP with with pyenv.

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

pyenvInstallation

pyenv安装

Following How can I use Homebrew to install both Python 2 and 3 on Mac?, I tried:

以下如何使用 Homebrew 在 Mac 上安装 Python 2 和 3?, 我试过:

$ pyenv install 3.6.5

Which erred with:

哪个错误:

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

What have I tried

我试过什么

  • Installing zlib: brew install zlib
  • 安装 zlib: brew install zlib

My question

我的问题

How can I install multiple Python environment with pyenvon MBP?

如何pyenv在 MBP 上安装多个 Python 环境?

回答by samsin

On Mojave, after installing Xcode command line tools, had to run the following:

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

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

回答by James Zaghini

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's answer didn't work for me. I didn't have a Packagesdir

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

回答by jayeff

The pyenv wiki has a page specific for common build problems. There are some possible solutions mentioned for the missing zlib error.

pyenv wiki 有一个专门针对常见构建问题的页面。对于缺少的 zlib 错误,提到了一些可能的解决方案。

I have the same ZipImportError but with the following command installation is successful:

我有相同的 ZipImportError 但使用以下命令安装成功:

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