版权声明:本文章是作者辛勤书写的成果,如需转载,请与作者联系,并保留作者信息以及原文链接,谢谢~~ https://blog.csdn.net/blueheart20/article/details/86671977
问题提出
环境: macos zsh,默认使用python2.7
尝试基于pyenv来管理多版本python
pyenv安装
brew install pyenv
安装成功
安装特定python
pyenv install 3.7.0
这里以3.7.0为例子来演示。
问题1
问题详情:
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/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190127214139.64700
Results logged to /var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190127214139.64700.log
Last 10 log lines:
checking for --with-icc... no
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190127214139.64700/Python-3.7.0':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make: *** No targets specified and no makefile found. Stop.
尝试如下:
- 检查 xcode
xcode-select --install
显示已经安装
2. xcode-select --reset
无效
3. 于是直接删除 /Library/Developer/Command Line Tools
4. 重新安装xcode基础类库
5. 重新尝试即可
问题2: zlib
问题错误信息:
# You may need to manually set your language environment
-> 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/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884
Results logged to /var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884.log
Last 10 log lines:
File "/private/var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884/Python-3.7.0/Lib/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/private/var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884/Python-3.7.0/Lib/ensurepip/__init__.py", line 204, in _main
default_pip=args.default_pip,
File "/private/var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884/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/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884/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
问题3: 依然是zlib
错误信息如下:
# You may need to manually set your language environment
-> 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/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884
Results logged to /var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884.log
Last 10 log lines:
File "/private/var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884/Python-3.7.0/Lib/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/private/var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884/Python-3.7.0/Lib/ensurepip/__init__.py", line 204, in _main
default_pip=args.default_pip,
File "/private/var/folders/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884/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/5s/tjdxcl_s1fg3gmyv27y4dfph0000gn/T/python-build.20190128084316.884/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有关的问题。
设置如下,在~/.zshrc中设置如下:
# For compilers to find zlib you may need to set:
export LDFLAGS="${LDFLAGS} -L/usr/local/opt/zlib/lib"
export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/zlib/include"
#For pkg-config to find zlib you may need to set:
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/zlib/lib/pkgconfig"
重新安装接口正常了
成功信息
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/tonychen/.pyenv/versions/3.7.0