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

Open
Voleking opened this Issue Sep 25, 2018 · 25 comments

Comments

Projects
None yet
@Voleking
Copy link

Voleking 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

This worked for me:

xcode-select --install
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

see Homebrew/homebrew-core#29176 (comment)

@Voleking Voleking closed this Sep 25, 2018

@Voleking Voleking reopened this Sep 25, 2018

@Voleking Voleking changed the title Install fails, "zlib not available" on macOS Mojave Install failed, "zlib not available" on macOS Mojave Sep 26, 2018

@joshfriend

This comment has been minimized.

Copy link
Member

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

@wenshi11019

This comment has been minimized.

Copy link

wenshi11019 commented Oct 8, 2018

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

@benmezger

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

joshfriend commented Oct 17, 2018

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

@ssbarnea

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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 minimized.

Copy link

fharper commented Nov 23, 2018

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target / solved it for me, thanks @Voleking .

Ostrzy added a commit to Ostrzy/dotfiles that referenced this issue Nov 25, 2018

Adjust setup for Kingfluencers
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

This comment has been minimized.

Copy link

tommyjcarpenter commented Nov 27, 2018

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

@moranmcsquid

This comment has been minimized.

Copy link

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.

@Voleking

This comment has been minimized.

Copy link

Voleking commented Dec 18, 2018

@moranmcsquid added it, thx.

@chikaram

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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?

@arnavb

This comment has been minimized.

Copy link

arnavb commented Dec 29, 2018

@tarrex Thanks for your solution! It worked perfectly for me.

@iamalisajid

This comment has been minimized.

Copy link

iamalisajid commented Jan 5, 2019

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.5.2 worked for me on MACOS Mojave.

@Cabalist

This comment has been minimized.

Copy link

Cabalist commented Jan 7, 2019

@iamalisajid This worked for me when the others did not. Thank you

@ssbarnea

This comment has been minimized.

Copy link

ssbarnea commented Jan 8, 2019

Instead of fixing the wiki, lets try to make pyenv bit smarter and add the missing part to CFLAGS at runtime, this would provide a much better user experience.

@joshfriend

This comment has been minimized.

Copy link
Member

joshfriend commented Jan 8, 2019

I don't have lots of time right now, so a pull request adding CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" on macOS would be much appreciated.

@jeffreyzh

This comment has been minimized.

Copy link

jeffreyzh commented Jan 9, 2019

thx to @Voleking. Your solution perfectly worked for me

sloria added a commit to sloria/dotfiles that referenced this issue Jan 20, 2019

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