最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】mac中安装pyenv install 3.5.2报错:zipimport.ZipImportError can’t decompress data zlib not available

Mac crifan 499浏览 0评论
折腾:
【未解决】mac中安装python3的多个不同版本
期间,去安装pyenv install 3.5.2,结果报错:
➜  ~ pyenv install 3.5.2
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.5.2.tar.xz...
-> 
https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
Installing Python-3.5.2...
patching file Lib/venv/scripts/posix/activate.fish
python-build: use readline from homebrew


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


Inspect or clean up the working tree at /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/python-build.20190607202138.62111
Results logged to /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/python-build.20190607202138.62111.log


Last 10 log lines:
  File "/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/python-build.20190607202138.62111/Python-3.5.2/Lib/ensurepip/__main__.py", line 4, in <module>
    ensurepip._main()
  File "/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/python-build.20190607202138.62111/Python-3.5.2/Lib/ensurepip/__init__.py", line 209, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/python-build.20190607202138.62111/Python-3.5.2/Lib/ensurepip/__init__.py", line 116, in bootstrap
    _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/python-build.20190607202138.62111/Python-3.5.2/Lib/ensurepip/__init__.py", line 40, in _run_pip
    import pip
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [Makefile:1059: install] Error 1
zlib Home Site
zipimport.ZipImportError: can’t decompress data; zlib not available
mac zipimport.ZipImportError: can’t decompress data; zlib not available
pyenv install 3.6.6 – zipimport.ZipImportError: can’t decompress data; zlib not available · Issue #13 · jiansoung/issues-list
➜  ~ brew install zlib
Updating Homebrew...
==> Downloading 
https://homebrew.bintray.com/bottles/zlib-1.2.11.mojave.bottle.tar.gz
######################################################################## 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
为了后续可能用到,再去:
vim ~/.bashrc
加上:
# 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"
结果问题依旧
Mojave使用pyenv安装python-zlib错误 | Pluviophile’s Blog
https://lisupy.github.io/2018/10/01/2018-10-01-Mojave使用pyenv安装python/#brew安装缺失的库
➜  ~ xcode-select -v
xcode-select version 2354.
怀疑是之前虽然安装了zlib,也给.bashrc加了变量,但是没生效。
所以再去生效:
➜  ~ source ~/.bashrc
➜  ~ echo $LDFLAGS
 -L/usr/local/opt/zlib/lib
➜  ~ echo $CPPFLAGS
 -I/usr/local/opt/zlib/include
➜  ~ echo $PKG_CONFIG_PATH
 /usr/local/opt/zlib/lib/pkgconfig
然后再去:
pyenv install 3.5.2
结果:可以了:
➜  ~ pyenv install 3.5.2
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.5.2.tar.xz...
-> https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
Installing Python-3.5.2...
patching file Lib/venv/scripts/posix/activate.fish
python-build: use readline from homebrew
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.5.2 to /Users/crifan/.pyenv/versions/3.5.2
即可。
【总结】
此处mac中:
pyenv install 3.5.2
报错:
zipimport.ZipImportError: can’t decompress data; zlib not available
原因:
mac中缺少zlib,(编译期间)找不到zib
解决办法:
安装zlib,且要加到环境变量中,要让(编译)能找到zlib
(1)安装zlib
brew install zlib
(2)加上合适的环境变量
编辑~/.bashrc
vim ~/.bashrc
(在最后)加上:
# 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"
让变量生效:
source ~/.bashrc

【可选】确认变量的确生效:
➜  ~ echo $LDFLAGS
 -L/usr/local/opt/zlib/lib
➜  ~ echo $CPPFLAGS
 -I/usr/local/opt/zlib/include
➜  ~ echo $PKG_CONFIG_PATH
 /usr/local/opt/zlib/lib/pkgconfig

转载请注明:在路上 » 【已解决】mac中安装pyenv install 3.5.2报错:zipimport.ZipImportError can’t decompress data zlib not available

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
94 queries in 0.148 seconds, using 20.68MB memory