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 · 22 comments

Comments

@jiansoung
Copy link
Owner

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
Copy link

It saves my time. Thanks

@Daletxt
Copy link

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
Copy link

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
Copy link

jocampo commented Mar 15, 2019

Thanks @antonagestam , worked like a charm!

@slhck
Copy link

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
Copy link

@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
Copy link

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
Copy link

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
Copy link

This saved me a lot of time!

@empeje
Copy link

empeje commented Apr 16, 2019

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

@Rabia23
Copy link

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
Copy link

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
Copy link

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
Copy link

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'

@ghost
Copy link

ghost 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
Copy link

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
Copy link

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
Copy link

sudo apt install zlib1g-dev

For me it didn't work, what worked is

sudo yum/apt-get install zlib-devel

@zoedaemon
Copy link

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
Copy link

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

@coolaj86
Copy link

Looks like this is safe to close out, no?

Also, my solution for Linux:
https://stackoverflow.com/questions/56999217/cant-fix-zipimport-zipimporterror-cant-decompress-data-zlib-not-available/65925481#65925481

If you don't have zlib1g-dev you're probably also missing libssl-dev too.

@ktavabi
Copy link

ktavabi commented Jun 4, 2022

I am still hitting a wall with installing versions of python < 3.10.0.

pyenv versions
  system
* 3.10.0 (set by /Users/me/.pyenv/version)
  3.8-dev-debug

I've managed to narrow it down to setting LD_LIBRARY_PATH during the build process...

LD_LIBRARY_PATH=: clang -DZLIB -DZLIB_SHARED -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DVPAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR="/Users/me/.pyenv/versions/3.6.8/openssl/ssl" -DENGINESDIR="/Users/me/.pyenv/versions/3.6.8/openssl/lib/engines-1.1" -O3 -D_REENTRANT -arch i386 -DL_ENDIAN -fomit-frame-pointer -fPIC -arch i386 -dynamiclib -current_version 1.1 -compatibility_version 1.1 -install_name /Users/me/.pyenv/versions/3.6.8/openssl/lib/libcrypto.1.1.dylib -o libcrypto.1.1.dylib -all_load libcrypto.a -Wl,-search_paths_first

This results in the following, and its head against the wall for me. So any help is appreciated.

ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)

I've installed my dependencies via mac ports and neither lazy or permanent shell variable settings worked out for me. I suspect there is a solution here but I can't make it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests