2019-01-19 mac os "xcrun: error: invalid active developer path" & “zipimport.ZipImportError: can...

在mac上安装一个python 3.7.0环境的时候,提示如下错误信息:

Anthonys-MacBook-Pro-2: anthony$ pyenv install -s 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.2 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/6g/6mxnqb850jvcdrgpg6zh7h200000gn/T/python-build.20190119102529.14304
Results logged to /var/folders/6g/6mxnqb850jvcdrgpg6zh7h200000gn/T/python-build.20190119102529.14304.log

Last 10 log lines:
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/6g/6mxnqb850jvcdrgpg6zh7h200000gn/T/python-build.20190119102529.14304/Python-3.7.0':
configure: error: C compiler cannot create executables
See `config.log' for more details
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Anthonys-MacBook-Pro-2: anthony$ xcode-select --install
xcode-select: note: install requested for command line developer tools
Anthonys-MacBook-Pro-2: anthony$ 

这个问题是 Xcode Command-line Tools 造成的,我们需要更新xcode。在终端窗口输入:

xcode-select --install

终端窗口并不会出现什么,mac会弹出一个窗口要你更新Xcode软件,点击更新,大概花几分钟下载安装更新,完了再次运行

pyenv install -s 3.7.0

本以为这次ok了,没想到再次出错:

Installing Python-3.7.0...
python-build: use readline from homebrew

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

Inspect or clean up the working tree at /var/folders/6g/6mxnqb850jvcdrgpg6zh7h200000gn/T/python-build.20190119104429.78337
Results logged to /var/folders/6g/6mxnqb850jvcdrgpg6zh7h200000gn/T/python-build.20190119104429.78337.log

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

试图用"$ brew install zlib* " 安装zlib包来解决,但是安装完以后仍然是同样故障。
查了一些资料,发现需要使用

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

再来:

Anthonys-MacBook-Pro-2: anthony$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Password:
installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path /
installer: The install was successful.

Anthonys-MacBook-Pro-2: anthony$ pyenv install -s 3.7.0
python-build: use openssl from homebrew
python-build: use readline from homebrew
Installing Python-3.7.0...
python-build: use readline from homebrew
Installed Python-3.7.0 to /Users/anthony/.pyenv/versions/3.7.0

这次终于顺利完成安装。

你可能感兴趣的:(2019-01-19 mac os "xcrun: error: invalid active developer path" & “zipimport.ZipImportError: can...)