MacOS 10.14下pyenv 安裝python3.7.0的錯誤 原

在MacOS10.14下,使用pyenv安裝python3.7.0的時候,報錯了,如下:

xwszt@Linxyz:~$ pyenv install 3.7.0
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.0.tar.xz...
-> https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
Installing Python-3.7.0...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.14 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/b_/4ggdxx_539g8cqp2wr2m5sph0000gn/T/python-build.20181012094932.14705
Results logged to /var/folders/b_/4ggdxx_539g8cqp2wr2m5sph0000gn/T/python-build.20181012094932.14705.log

Last 10 log lines:
  File "/private/var/folders/b_/4ggdxx_539g8cqp2wr2m5sph0000gn/T/python-build.20181012094932.14705/Python-3.7.0/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/private/var/folders/b_/4ggdxx_539g8cqp2wr2m5sph0000gn/T/python-build.20181012094932.14705/Python-3.7.0/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/b_/4ggdxx_539g8cqp2wr2m5sph0000gn/T/python-build.20181012094932.14705/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/var/folders/b_/4ggdxx_539g8cqp2wr2m5sph0000gn/T/python-build.20181012094932.14705/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

注意最後兩行,說明找不到zlib。

在網上找了很多文章,多數說要制定zlib的目錄 /usr/include。事實上應該是10.14在xcode-select --install中去除了zlib,所以應該自己手動安裝zlib。同樣使用brew安裝:

$ brew install zlib
==> Downloading https://homebrew.bintray.com/bottles/zlib-1.2.11.mojave.bottle.t
######################################################################## 100.0%
==> Pouring zlib-1.2.11.mojave.bottle.tar.gz
==> Caveats
zlib is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

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"

For pkg-config to find zlib you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"

==> Summary
  /usr/local/Cellar/zlib/1.2.11: 12 files, 373KB

按照提示,還需要設置環境變量:

$ export LDFLAGS="-L/usr/local/opt/zlib/lib"
$ export CPPFLAGS="-I/usr/local/opt/zlib/include"

然後執行命令安裝python

$ pyenv install 3.7.0
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.0.tar.xz...
-> https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
Installing Python-3.7.0...
python-build: use readline from homebrew
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.7.0 to /Users/xwszt/.pyenv/versions/3.7.0

到此爲止,python3.7.0安裝完成了,當然這裏沒有將sqlite3編譯完成,這個可以通過brew install sqlite安裝即可了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章