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

Install failed, "zlib not available" on macOS Mojave #1219

Closed
tshu-w opened this issue Sep 25, 2018 · 59 comments
Closed

Install failed, "zlib not available" on macOS Mojave #1219

tshu-w opened this issue Sep 25, 2018 · 59 comments

Comments

@tshu-w
Copy link

@tshu-w tshu-w commented Sep 25, 2018

Description

  • Platform information (e.g. Ubuntu Linux 16.04): macOS Mojave 10.14
  • OS architecture (e.g. amd64):amd64
  • pyenv version: 1.2.7
  • Python version: 3.7.0 & 2.7.15
  • C Compiler information (e.g. gcc 7.3): Apple LLVM version 10.0.0 (clang-1000.11.45.2)
  • Please attach verbose build log as gist

see Homebrew/homebrew-core#29176 (comment)

Temporary workaround:

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install ...
@tshu-w tshu-w closed this Sep 25, 2018
@tshu-w tshu-w reopened this Sep 25, 2018
@tshu-w tshu-w changed the title Install fails, "zlib not available" on macOS Mojave Install failed, "zlib not available" on macOS Mojave Sep 26, 2018
@joshfriend
Copy link
Member

@joshfriend joshfriend commented Oct 2, 2018

I just upgraded to Mojave and had the same problem. The commandline tools headers package fixed it, but it feels like a hack

@DC-ing
Copy link

@DC-ing DC-ing commented Oct 8, 2018

I have the same problem, but I can solve it after watch wiki

@benmezger
Copy link

@benmezger benmezger commented Oct 9, 2018

Solved it by running: sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

@codezakh
Copy link

@codezakh codezakh commented Oct 10, 2018

Apparently this is happening because Xcode Command Line tools no longer installs needed headers in /include. You have to run a separate command to install the needed headers.

See https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes.

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. As a workaround, an extra package is provided which will install the headers to the base system. In a future release, this package will no longer be provided. You can find this package at:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

To make sure that you're using the intended version of the command line tools, run xcode-select -s or xcode select -s /Library/Developer/CommandLineTools after installing.

@joshfriend
Copy link
Member

@joshfriend joshfriend commented Oct 10, 2018

I've added this to the suggested build environment and common build problems wiki pages for now until a better solution is found

@qianxiaowei
Copy link

@qianxiaowei qianxiaowei commented Oct 11, 2018

I'm now working on Mojave, and followed the solution provided by @thetylerwolf , and it works.

I'm running OS X Sierra and the above didn't help for me. Found this solution here: https://medium.com/@pimterry/setting-up-pyenv-on-os-x-with-homebrew-56c7541fd331
and it did work.

CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" \
PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 \
pyenv install -v 3.6.0
@chenguanda
Copy link

@chenguanda chenguanda commented Oct 11, 2018

I'm now working on Mojave too, followed the solution provded by @Voleking, I fixed the error of zlib, but not openssl ,

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

I fix it by run the following command

CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install 3.6.0

@zanderzhng
Copy link

@zanderzhng zanderzhng commented Oct 12, 2018

I didn't have CLT installed in my Mojave so I couldn't install the headers pkg.
@qianxiaowei 's code worked for me, but I'm wondering if following commands would be enough. below code are enough.

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 3.7.0
@ssbarnea
Copy link

@ssbarnea ssbarnea commented Oct 17, 2018

Indeed, the wiki page is misleading as it contains commands that would not work with current released versions of Mojave and xcode 10 but the simple command above works perfects.

Please fix this so we don't need to manually hack CFLAGS to amke it work.

@joshfriend
Copy link
Member

@joshfriend joshfriend commented Oct 17, 2018

@ssbarnea you are always welcome to edit the wiki if you think it is incorrect.

@ssbarnea
Copy link

@ssbarnea ssbarnea commented Oct 18, 2018

Considering that from now on we will continue to see this problem more I think it would be smart to make pyenv define the CFLAGS itself when is not already defined. This should sort the problem for the vast majority of the users.

For me the problem is sorted as I added it to my ~/.profile alongside other similar hacks related to compilation under MacOS. Still, I do not expect this do be easily doable by every pyenv MacOS user. The best is when it just works ;)

I know that some could argue that this should be done by brew itself, but I really doubt brew would do such a change soon enough to make a difference. By the time they will do, we would probably see 100+ more complaints here, or even worse new duplicate bugs.

@DrewHoo
Copy link

@DrewHoo DrewHoo commented Nov 13, 2018

Can we link #454 to this issue? It is the exact same problem, but the solution differs if you're on Mojave.

@fharper

This comment has been hidden.

Ostrzy added a commit to Ostrzy/dotfiles that referenced this issue Nov 25, 2018
As tomorrow I start new job and will have to setup new machine, I've
decided that the simplest way to speed up this process is to simply
adjust scripts for this exact machine.

Fix for Python compilation was found on pyenv github issue[1] and
doesn't seem to be final solution. I couldn't really tell what to check
to ensure we're not installing again so I just check if it was an
upgrade or not to tell whether something changed.

[1] pyenv/pyenv#1219
@tommyjcarpenter
Copy link

@tommyjcarpenter tommyjcarpenter commented Nov 27, 2018

@Voleking solution also worked for me on a fresh copy of OSX 10.14.1

@moranmcsquid
Copy link

@moranmcsquid moranmcsquid commented Dec 17, 2018

@Voleking Would you mind also adding xcode-select --install to your solution.

For most people that would be a "duh", but there are conditions in which you could have installed XCode and have a compiler without having the commandline tools installed.

@tshu-w
Copy link
Author

@tshu-w tshu-w commented Dec 18, 2018

@moranmcsquid added it, thx.

@chikaram
Copy link

@chikaram chikaram commented Dec 19, 2018

I had a clean installed Mojave, installed Xcode, Homebrew, pyenv, zlib and still had this issue.

zipimport.ZipImportError: can't decompress data; zlib not available

That means the problem isn't fixed yet at the moment. (Dec 19, 2018)

Anyway, super thx to @Voleking. Your solution perfectly worked for me.

@tarrex
Copy link

@tarrex tarrex commented Dec 19, 2018

Well, if you use the brew, zlib not available means that pyenv compilers can't find zlib header files. The brew has told you in brew info zlib that

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"

so just execute

export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"

and then

pyenv install 3.7.1

There is another warning WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? also like this, execute

export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/sqlite/include"

then install your version. Worked for me.

  • macOS Mojave 10.14.1
  • pyenv 1.2.8
@pradyunsg
Copy link

@pradyunsg pradyunsg commented Dec 29, 2018

@joshfriend Thoughts on detecting this case early, in pyenv install's code and then calling it out before calling into python-build or maybe handling this case at the python-build level?

It could also suggest remedies or maybe try to use the brew zlib if possible; like readline?

@mamboer

This comment was marked as spam.

@slhck
Copy link

@slhck slhck commented May 14, 2019

@HaoweiCh Please read #1219 (comment) — one of the project members believes that it's better to hide this solution, which leads to the fact that other users cannot find it, then post it again, etc. While I completely disagree with this approach, it's at their discretion. Let's just hope that a fix will be out soon.

@joshfriend
Copy link
Member

@joshfriend joshfriend commented May 14, 2019

I had been marking the reposts of that solution as spam because they were in my view spam. If a solution has already been posted, people should leave a 👍 to indicate that it helped them instead of continually reposting the same thing and adding noise to the thread. The legacy headers pkg install is the current solution listed in the common build problems wiki as well.

Since hiding the duplicates is still causing confusion, I've unhidden them.

@HaoweiCh
Copy link

@HaoweiCh HaoweiCh commented May 15, 2019

@joshfriend sorry, I didn't read this issue carefully. and I've already deleted the not that proper solution. :)

@adithyabsk
Copy link
Contributor

@adithyabsk adithyabsk commented Jun 4, 2019

Just sum up the current status of this issue, it seems like there is a current solution that breaks tests that @joshfriend has worked on. Just wanted to bump this issue to see where it stands on the docket among other issues as it breaks installation scripts.

@joshfriend joshfriend mentioned this issue Jun 9, 2019
1 of 7 tasks complete
mikeroll added a commit to mikeroll/pyenv that referenced this issue Jun 10, 2019
mikeroll added a commit to mikeroll/pyenv that referenced this issue Jun 10, 2019
mikeroll added a commit to mikeroll/pyenv that referenced this issue Jun 10, 2019
mikeroll added a commit to mikeroll/pyenv that referenced this issue Jun 10, 2019
mikeroll added a commit to mikeroll/pyenv that referenced this issue Jun 10, 2019
mikeroll added a commit to mikeroll/pyenv that referenced this issue Jun 10, 2019
mikeroll added a commit to mikeroll/pyenv that referenced this issue Jun 10, 2019
joshfriend added a commit that referenced this issue Jun 11, 2019
@joshfriend
Copy link
Member

@joshfriend joshfriend commented Jun 11, 2019

Big thanks to @mikeroll for coming up with a solution that didn't break the entire test suite like mine did 😆

@Croydon
Copy link

@Croydon Croydon commented Jun 11, 2019

Now we only seem to need a new release of pyenv 😄

caferelgin added a commit to caferelgin/aws-elastic-beanstalk-cli-setup that referenced this issue Jul 8, 2019
Hi, I've encountered another problem on OS X installation so I wanted to contribute with the solution I found on pyenv/pyenv#1219
@Zeesy
Copy link

@Zeesy Zeesy commented Aug 6, 2019

Solved it by running: sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

This worked for me, but only after running
export PATH="$PATH:/Library/Frameworks/Python.framework/Versions/3.7/bin"
(see this post)

@keisuke-nakata
Copy link

@keisuke-nakata keisuke-nakata commented Sep 25, 2019

Finally, my workaround is:

CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" CFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix sqlite)/include" LDFLAGS="-L$(brew --prefix zlib)/lib -L$(brew --prefix sqlite)/lib" pyenv install 3.7.3

If you have a trouble with ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib? error even when you added LDFLAGS="-L$(brew --prefix openssl)/lib" and CFLAGS="-I$(brew --prefix openssl)/include" .

@rickmark
Copy link

@rickmark rickmark commented Sep 1, 2020

One can make this a little easier by adding that to ENV as PYTHON_CONFIGURE_OPTS. Using these env variables (which fix a lot of missing packages on 11.0) one can then simply pyenv install 3.8.5

# added to .zshrc

export PYTHON_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)"
export CFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix sqlite)/include -I$(brew --prefix bzip2)/include"
export LDFLAGS="-L$(brew --prefix zlib)/lib -L$(brew --prefix sqlite)/lib -L$(brew --prefix bzip2)/lib"
@ben-xD
Copy link

@ben-xD ben-xD commented Nov 16, 2020

Although this issue is old, the same error message happens on macOS Big Sur.

Just wanted to duplicate what Zheaoli wrote in a different thread:

LDFLAGS="-L$(xcrun --show-sdk-path)/usr/lib" pyenv install 3.8.6 this is working for me

Using /lib instead of /include as thread-OP allowed me to install 3.8.6.

@lesterlo
Copy link

@lesterlo lesterlo commented Dec 2, 2020

Although this issue is old, the same error message happens on macOS Big Sur.

Just wanted to duplicate what Zheaoli wrote in a different thread:

LDFLAGS="-L$(xcrun --show-sdk-path)/usr/lib" pyenv install 3.8.6 this is working for me

Using /lib instead of /include as thread-OP allowed me to install 3.8.6.

install the zlib library from homebrew
then add this line export LDFLAGS="-L/usr/local/opt/zlib/lib $LDFLAGS" to your shell can also solve the problem.

@fabiom91
Copy link

@fabiom91 fabiom91 commented Dec 7, 2020

Well, if you use the brew, zlib not available means that pyenv compilers can't find zlib header files. The brew has told you in brew info zlib that

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"

so just execute

export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"

and then

pyenv install 3.7.1

There is another warning WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? also like this, execute

export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/sqlite/include"

then install your version. Worked for me.

  • macOS Mojave 10.14.1
  • pyenv 1.2.8

Thanks @tarrex
I would also mention brew install zlib for dumb people like me eh eh

@dominicfraser
Copy link

@dominicfraser dominicfraser commented Jan 2, 2021

It appears this has been fixed in the 1.2.12 release 🎉

https://github.com/pyenv/pyenv/releases/tag/v1.2.12

@VGerris
Copy link

@VGerris VGerris commented Jan 3, 2021

I am using 1.2.21 and still have this issue on MacOS Big Sur (11.1) - seems there is an open issue for that:
#1764

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

Successfully merging a pull request may close this issue.