Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyenv install 3.6.6 - zipimport.ZipImportError: can't decompress data; zlib not available #13

Open
jiansoung opened this issue Oct 28, 2018 · 20 comments

Comments

@jiansoung
Copy link
Owner

@jiansoung jiansoung commented Oct 28, 2018

pyenv install 3.6.6 - zipimport.ZipImportError: can't decompress data; zlib not available

macOS + Homebrew + Pyenv

Issue

$ pyenv install 3.6.6
python-build: use openssl from homebrew
python-build: use readline from homebrew
Installing Python-3.6.6...
python-build: use readline from homebrew

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

Inspect or clean up the working tree at /var/folders/9s/4dz5cwfj0dv6j_1_k8nlnd5m0000gn/T/python-build.20181028140503.9082
Results logged to /var/folders/9s/4dz5cwfj0dv6j_1_k8nlnd5m0000gn/T/python-build.20181028140503.9082.log

Last 10 log lines:
  File "/private/var/folders/9s/4dz5cwfj0dv6j_1_k8nlnd5m0000gn/T/python-build.20181028140503.9082/Python-3.6.6/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/private/var/folders/9s/4dz5cwfj0dv6j_1_k8nlnd5m0000gn/T/python-build.20181028140503.9082/Python-3.6.6/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/private/var/folders/9s/4dz5cwfj0dv6j_1_k8nlnd5m0000gn/T/python-build.20181028140503.9082/Python-3.6.6/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/private/var/folders/9s/4dz5cwfj0dv6j_1_k8nlnd5m0000gn/T/python-build.20181028140503.9082/Python-3.6.6/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

Fix

Install zlib

brew install zlib

Add the following to your ~/.zshrc (if you use zsh)

the following content partly from the output of brew install zlib

DO NOT FORGET TO ADD ${LDFLAGS}, ${CPPFLAGS}, ${PKG_CONFIG_PATH} !

# 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"
@tuanluu-agilityio

This comment has been minimized.

Copy link

@tuanluu-agilityio tuanluu-agilityio commented Feb 26, 2019

It saves my time. Thanks

@Daletxt

This comment has been minimized.

Copy link

@Daletxt Daletxt commented Feb 28, 2019

Thank you!
And other libs are also needed, such as SQLite3
and we also need to configure ~/.zshrc according to homebrew's information.
And:!!! the .zshrc file such as:

#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"
export LDFLAGS="${LDFLAGS} -L/usr/local/opt/sqlite/lib"
export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/sqlite/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"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/sqlite/lib/pkgconfig"
are OK.
But

#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"

export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"
are not OK!
I think maybe we need "${LDFLAGS} 、${CPPFLAGS} 、${PKG_CONFIG_PATH} ".
And I need to source ~/.zshrc every time I used pyenv install xxx.

@antonagestam

This comment has been minimized.

Copy link

@antonagestam antonagestam commented Mar 6, 2019

You don't need to add anything permanently to your dotfiles, the flags just need to be set during compile time. So just set the environment variables in your shell session. This worked for me:

$ brew install zlib
$ brew install sqlite
$ export LDFLAGS="${LDFLAGS} -L/usr/local/opt/zlib/lib"
$ export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/zlib/include"
$ export LDFLAGS="${LDFLAGS} -L/usr/local/opt/sqlite/lib"
$ export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/sqlite/include"
$ export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/zlib/lib/pkgconfig"
$ export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/sqlite/lib/pkgconfig"
$ pyenv install 3.6.8
@jocampo

This comment has been minimized.

Copy link

@jocampo jocampo commented Mar 15, 2019

Thanks @antonagestam , worked like a charm!

@slhck

This comment has been minimized.

Copy link

@slhck slhck commented Mar 21, 2019

Thanks @antonagestam for the instructions (I just wish you removed the $ so this could be copied straight into a terminal).

I can't believe this is the only resource on the web for this problem. I haven't had this issue so far, using Homebrew and pyenv. What caused this change?

@antonagestam

This comment has been minimized.

Copy link

@antonagestam antonagestam commented Mar 21, 2019

@slhck It is not the only resource for this on the web, it is a reported issue on the pyenv project: pyenv/pyenv#1219

The dollar signs are in there to prevent people from copy-pasting code without knowing what they're doing.

@slhck

This comment has been minimized.

Copy link

@slhck slhck commented Mar 21, 2019

Thanks for the link. I was a little imprecise in my statement, but this was the most prominent search result I got for this particular error, with a simple fix presented. The others being pyenv/pyenv#454 (which suggests xcode-select, which I did), and this Q&A post, which is about Unix. And then you get to some other Stack Overflow posts that finally, after following another redirect, point you to the Pyenv issue.

@janjur

This comment has been minimized.

Copy link

@janjur janjur commented Apr 1, 2019

cat <<EOT >> ~/.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"
EOT

Edit: above is permanent, thus (as @antonagestam said) wrong. His answer for the lazy:

brew install zlib
brew install sqlite
export LDFLAGS="${LDFLAGS} -L/usr/local/opt/zlib/lib"
export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/zlib/include"
export LDFLAGS="${LDFLAGS} -L/usr/local/opt/sqlite/lib"
export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/sqlite/include"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/zlib/lib/pkgconfig"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/sqlite/lib/pkgconfig"
pyenv install 3.6.8
@frankie-ug

This comment has been minimized.

Copy link

@frankie-ug frankie-ug commented Apr 9, 2019

This saved me a lot of time!

@empeje

This comment has been minimized.

Copy link

@empeje empeje commented Apr 16, 2019

For someone using fish shell can check this out https://gist.github.com/empeje/fd7b654b2e57e33f74b833fedcd5f51e

@Rabia23

This comment has been minimized.

Copy link

@Rabia23 Rabia23 commented Apr 18, 2019

You don't need to add anything permanently to your dotfiles, the flags just need to be set during compile time. So just set the environment variables in your shell session. This worked for me:

$ brew install zlib
$ brew install sqlite
$ export LDFLAGS="${LDFLAGS} -L/usr/local/opt/zlib/lib"
$ export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/zlib/include"
$ export LDFLAGS="${LDFLAGS} -L/usr/local/opt/sqlite/lib"
$ export CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/sqlite/include"
$ export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/zlib/lib/pkgconfig"
$ export PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/sqlite/lib/pkgconfig"
$ pyenv install 3.6.8

Thanks, @antonagestam for instructions. It really helped a lot.

@dews

This comment has been minimized.

Copy link

@dews dews commented Apr 23, 2019

For fish shell

brew install zlib
brew install sqlite
set -g -x LDFLAGS "$LDFLAGS  -L/usr/local/opt/zlib/lib"
set -g -x CPPFLAGS "$CPPFLAGS  -I/usr/local/opt/zlib/include"
set -g -x LDFLAGS "$LDFLAGS  -L/usr/local/opt/sqlite/lib"
set -g -x CPPFLAGS "$CPPFLAGS  -I/usr/local/opt/sqlite/include"
set -g -x PKG_CONFIG_PATH "$PKG_CONFIG_PATH  /usr/local/opt/zlib/lib/pkgconfig"
set -g -x PKG_CONFIG_PATH "$PKG_CONFIG_PATH  /usr/local/opt/sqlite/lib/pkgconfig"
pyenv install 3.6.8
@kylefoley76

This comment has been minimized.

Copy link

@kylefoley76 kylefoley76 commented May 3, 2019

Ok, I loved the problem on a Mac using Mojave OS. I first removed pyenv

rm -rf "$HOME/.pyenv"

Then installed it using homebrew

brew install pyenv

That did it. The website where I got the info was here:
pyenv/pyenv#1281

@RulerOf

This comment has been minimized.

Copy link

@RulerOf RulerOf commented May 9, 2019

Thanks @antonagestam .

To cover future installs, I used an alias to turn the concept you're using that sets those values every time I invoke pyenv by adding this to my ~/.bash_profile:

alias pyenv='LDFLAGS="${LDFLAGS} -L/usr/local/opt/zlib/lib -L/usr/local/opt/sqlite/lib" CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/zlib/include -I/usr/local/opt/sqlite/include" PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/zlib/lib/pkgconfig /usr/local/opt/sqlite/lib/pkgconfig" pyenv'
@xvindiex

This comment has been minimized.

Copy link

@xvindiex xvindiex commented May 12, 2019

@RulerOf

Thanks @antonagestam .

To cover future installs, I turned used an alias to turn the concept you're using that sets those values every time I invoke pyenv by adding this to my ~/.bash_profile:

alias pyenv='LDFLAGS="${LDFLAGS} -L/usr/local/opt/zlib/lib -L/usr/local/opt/sqlite/lib" CPPFLAGS="${CPPFLAGS} -I/usr/local/opt/zlib/include -I/usr/local/opt/sqlite/include" PKG_CONFIG_PATH="${PKG_CONFIG_PATH} /usr/local/opt/zlib/lib/pkgconfig /usr/local/opt/sqlite/lib/pkgconfig" pyenv'

The alias worked very well for me!!! 👌🏻

@idcrook

This comment has been minimized.

Copy link

@idcrook idcrook commented May 27, 2019

ran into similar problem on Linux Mint (Ubuntu) found this issue during searching. did the following:

sudo apt install zlib1g-dev

did more googlings/search pyenv issues, then found this page that might cover additional build issues (assorted Linux and macOS listed), and it lists many other potential build dependencies

https://github.com/pyenv/pyenv/wiki/Common-build-problems

@Sjors

This comment has been minimized.

Copy link

@Sjors Sjors commented Jun 4, 2019

The pyenv alias breaks pyenv init in .bash_profile for me.

Another approach is to use /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk as explained here

The Apple notes suggest that this is a bug in PyEnv:

The command line tools will search the SDK for system headers by default. However, some software may fail to build correctly against the SDK and require macOS headers to be installed in the base system under /usr/include. If you are the maintainer of such software, we encourage you to update your project to work with the SDK or file a bug report for issues that are preventing you from doing so

@ishandutta2007

This comment has been minimized.

Copy link

@ishandutta2007 ishandutta2007 commented Aug 27, 2019

sudo apt install zlib1g-dev

For me it didn't work, what worked is

sudo yum/apt-get install zlib-devel
@zoedaemon

This comment has been minimized.

Copy link

@zoedaemon zoedaemon commented Sep 20, 2019

ran into similar problem on Linux Mint (Ubuntu) found this issue during searching. did the following:

sudo apt install zlib1g-dev

did more googlings/search pyenv issues, then found this page that might cover additional build issues (assorted Linux and macOS listed), and it lists many other potential build dependencies

https://github.com/pyenv/pyenv/wiki/Common-build-problems

thanks it's worked on debian 9 GCP

@eliethesaiyan

This comment has been minimized.

Copy link

@eliethesaiyan eliethesaiyan commented Nov 5, 2019

ran into similar problem on Linux Mint (Ubuntu) found this issue during searching. did the following:

sudo apt install zlib1g-dev

did more googlings/search pyenv issues, then found this page that might cover additional build issues (assorted Linux and macOS listed), and it lists many other potential build dependencies

https://github.com/pyenv/pyenv/wiki/Common-build-problems

I can confirm that this fixed my problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.