在MacOS10.14下,使用pyenv安装python3.7.0的时候,报错了,如下:
xwszt@Linxyz:~$ pyenv install 3.7.0python-build: use openssl from homebrewpython-build: use readline from homebrewDownloading Python-3.7.0.tar.xz...-> https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xzInstalling Python-3.7.0...python-build: use readline from homebrewBUILD 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.14705Results logged to /var/folders/b_/4ggdxx_539g8cqp2wr2m5sph0000gn/T/python-build.20181012094932.14705.logLast 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, insys.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._internalzipimport.ZipImportError: can't decompress data; zlib not availablemake: *** [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==> Caveatszlib is keg-only, which means it was not symlinked into /usr/local,because macOS already provides this software and installing another version inparallel 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.0python-build: use openssl from homebrewpython-build: use readline from homebrewDownloading Python-3.7.0.tar.xz...-> https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xzInstalling Python-3.7.0...python-build: use readline from homebrewWARNING: 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安装即可了。