7

操作系统: MacOS 10.14 Beta

目标:通过 PYENV 安装 Python 3.7.0

尝试通过 pyenv 安装 python 3.7.0 时出现此错误,我该如何解决?

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

尝试修复的步骤:

1)重新安装XCODE

2)重新安装 XCODE 命令行工具

3)阅读 Stack Overflow 上的类似错误

替代问题:

1) zlib 应该是预装的,我可能会遇到什么样的问题?

2)将python手动安装到pyenv也可以被pyenv识别的另一种方法是什么?

4

2 回答 2

2

特别是对于 Python 3.7.0,我成功地完成了以下操作:

运行 info zlib 时,Brew 提供了一些很好的说明

$ brew info zlib
...
For compilers to find zlib you may need to set:
  export LDFLAGS="-L/usr/local/opt/zlib/lib"
  export CPPFLAGS="-I/usr/local/opt/zlib/include"
...

因此,根据这些说明,我只需剪切/粘贴 FTW :)

$ export LDFLAGS="-L/usr/local/opt/zlib/lib"
$ export CPPFLAGS="-I/usr/local/opt/zlib/include"
$ pyenv install 3.7.0   # Succeeded
于 2018-12-26T18:47:49.750 回答
0

我有同样的问题。首先我尝试手动安装python

./configure --prefix /usr/local/var/pyenv/versions/3.5.5/
make
make install

构建完成,但我也收到有关 openssl 和 zlib 的错误。然后我再次尝试更改构建环境:

export CPPFLAGS="-I/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I$(brew --prefix openssl)/include"
export LDFLAGS="-L/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -L$(brew --prefix openssl)/lib"

哪个成功了。

最后我在同一个shell中运行(两个导出变量):

pyenv install 3.5.5

也成功了:-) HTH

于 2018-08-07T21:21:15.833 回答