Search code examples
bashmacospython-2.7homebrewpyenv

ERROR: The Python zlib extension was not compiled. Missing the zlib?


I'm trying to install Python 2.7.7 using Homebrew AND pyenv on my Mac (MacBook Air, OSX 12.5 Monterrey, 1.6 GHz Dual-Core Intel Core i5) but keep getting this “Missing zlib” error.

Just for reference, I have done the following:

  1. When I Installed pyenv, I ran command nano ~/.bashrc (I'm using bash shell) - and pasted and saved on /.bashrc ---> eval "$(pyenv init -)"
  2. then I ran pyenv install 2.7.7 (didn't work and found online step 3.)
  3. CPPFLAGS="-I$(brew --prefix zlib)/include" pyenv install -v 2.7.7 (Again, same error and did step 4.)
  4. ran brew reinstall zlib and overrode on "/.bashrc" eval "$(pyenv init -)" to:
export PATH="/usr/local/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/bzip2/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include"

-------------Start of Error ----------------

rm -f /Users/victor/.pyenv/versions/2.7.7/bin/python2
(cd /Users/victor/.pyenv/versions/2.7.7/bin; ln -s python2.7 python2)
rm -f /Users/victor/.pyenv/versions/2.7.7/bin/python2-config
(cd /Users/victor/.pyenv/versions/2.7.7/bin; ln -s python2.7-config python2-config)
rm -f /Users/victor/.pyenv/versions/2.7.7/bin/python-config
(cd /Users/victor/.pyenv/versions/2.7.7/bin; ln -s python2-config python-config)
test -d /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig || /usr/bin/install -c -d -m 755 /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig
rm -f /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig/python2.pc
(cd /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig; ln -s python-2.7.pc python2.pc)
rm -f /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig/python.pc
(cd /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig; ln -s python2.pc python.pc)
rm -f /Users/victor/.pyenv/versions/2.7.7/share/man/man1/python2.1
(cd /Users/victor/.pyenv/versions/2.7.7/share/man/man1; ln -s python2.7.1 python2.1)
rm -f /Users/victor/.pyenv/versions/2.7.7/share/man/man1/python.1
(cd /Users/victor/.pyenv/versions/2.7.7/share/man/man1; ln -s python2.1 python.1)
ERROR: The Python zlib extension was not compiled. Missing the zlib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


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

Inspect or clean up the working tree at /var/folders/__/1_b0871s7fl7fpwydg4ycjj80000gn/T/python-build.20220729111901.75727
Results logged to /var/folders/__/1_b0871s7fl7fpwydg4ycjj80000gn/T/python-build.20220729111901.75727.log

Last 10 log lines:
(cd /Users/victor/.pyenv/versions/2.7.7/bin; ln -s python2-config python-config)
test -d /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig || /usr/bin/install -c -d -m 755 /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig
rm -f /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig/python2.pc
(cd /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig; ln -s python-2.7.pc python2.pc)
rm -f /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig/python.pc
(cd /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig; ln -s python2.pc python.pc)
rm -f /Users/victor/.pyenv/versions/2.7.7/share/man/man1/python2.1
(cd /Users/victor/.pyenv/versions/2.7.7/share/man/man1; ln -s python2.7.1 python2.1)
rm -f /Users/victor/.pyenv/versions/2.7.7/share/man/man1/python.1
(cd /Users/victor/.pyenv/versions/2.7.7/share/man/man1; ln -s python2.1 python.1)
Victors-MacBook-Air:~ victor$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Victors-MacBook-Air:~ victor$ 
Victors-MacBook-Air:~ victor$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Victors-MacBook-Air:~ victor$ 
Victors-MacBook-Air:~ victor$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Victors-MacBook-Air:~ victor$ 
Victors-MacBook-Air:~ victor$ software update
-bash: software: command not found

------------- End of Error -----------------

Any idea?.... Please let me know... I'd highly appreciate it


Solution

  • With a similar configuration, 2018 MBA on Monterey, I was having the same problem as you with pyenv install 2.7.6

    I was able to go past the missing zlib issue with the following additions to the shell's profile:

    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
    
    export LDFLAGS="-L/usr/local/opt/zlib/lib"
    export CPPFLAGS="-I/usr/local/opt/zlib/include"
    export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"
    

    As a side note, the installation still didn't go through due to a different issue: enter image description here

    That OpenSSL issue has to do with OpenSSL 1.0 being EOL, more info here.

    At the end I just went with 2.7.14 which is OpenSSL 2.0 compatible and good enough for my use case.