Macos在zsh下基于pyenv安装python版本中的问题汇总

问题提出

环境: 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.

尝试如下:

  1. 检查 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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值