Pyenv: macOS High Sierra: ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Created on 29 Sep 2017  Â·  41Comments  Â·  Source: pyenv/pyenv

I am having this issue on mac os high sierra(10.13) even with setting CFLAGS and LDFLAGS correctly using brew --prefix

macOS

Most helpful comment

brew install pyenv doesn't help.
In fact, I install openssl and pyenv both from homebrew.
CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install 3.6.3 does fix this issue.

All 41 comments

@uber1geek

I can finish this step successfully.

first:
brew install readline openssl xz

and Homebrew said both readline and openssl is keg-only. so I wrote a .sh file to export environment variables:

# ~/.env-exporter
# about zlib
export CFLAGS="-I$(xcrun --show-sdk-path)/usr/include"
# about readline
export CFLAGS="-I$(brew --prefix readline)/include $CFLAGS"
export LDFLAGS="-L$(brew --prefix readline)/lib $LDFLAGS"
# about openssl
export CFLAGS="-I$(brew --prefix openssl)/include $CFLAGS"
export LDFLAGS="-L$(brew --prefix openssl)/lib $LDFLAGS"
# about SQLite (maybe not necessary)
export CFLAGS="-I$(brew --prefix sqlite)/include $CFLAGS"
export LDFLAGS="-L$(brew --prefix sqlite)/lib $LDFLAGS"

every time I want install a Python:

> source ~/.env-exporter
> pyenv install -v 2.7.13

I failed at the step of installing pip, cause of could not build the pyexpat module.

Hope helpful, and wish I can install 2.7.13 & 3.6.2

I'm currently experiencing this issue on a clean install of High Sierra. I was able to get openssl recognized using the above script, however I'm now failing because pyexpat can't be found (as referenced in the bottom of the last post). Is this a known issue?

I would suggest removing the old installation and install using homebrew. The problem turned out to be the openssl hadn't actually successfully installed (even though homebrew reported that it had). run brew uninstall openssl && brew install openssl && CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install 3.6.2

or simply, brew install pyenv

@uber1geek You are right. Do not install pyenv via pyenv-installer, instead of brew.

This can be solved pretty easily without installing homebrew. See my comment here https://github.com/pyenv/pyenv/issues/950#issuecomment-334612904

I started getting this issue once I upgraded to High Sierra. I followed the instructions above to uninstall and reinstall openssl and it fixed the issue -- I can now compile python successfully.

Thanks!

brew install pyenv doesn't help.
In fact, I install openssl and pyenv both from homebrew.
CFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix openssl)/lib" pyenv install 3.6.3 does fix this issue.

I was running into the same issue on High Sierra after installing pyenv, xz, readline, and openssl all from homebrew.. but as @Voleking stated, setting CFLAGS and LDFLAGS works..

to not have to type it in every time just add the following alias to your .profile, .bashrc, .zshrc or whatever..

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

I have the same problem, even when setting CFLAGS and LDFLAGS and suggested.

Any other suggestions that worked?

Edit: I missed the earlier comment where readline was installed as keg-only. The additional flags from @BruceFrankWang work.

@wdeer , this actually makes your shell start up a lot of slower, as the commands included in alias are being expanded every time the shell is run. On my 2015 MBP it gives a few seconds of delay.

I came here because I also have the same problem. Looking into other solutions.

EDIT: it looks like MacPorts are more than enough for me. No problems with installing different Python versions, I'm happily running 27, 33, 34, 35, 36 side-by-side. I do realise pyenv has a different scope of usage, but for Mac users who want to have different versions of Python, I'd say -- go MacPorts.

Homebrew ATM does not support multiple Python versions.

Guys if you're using brew and you hit this problem, the most recent version actually works now... Run these commands:
brew unlink pyenv
brew install pyenv --HEAD
it should work now...

@heynairb do you know if there's a workaround for missing pyexpat? When I try to build python on High Sierra I get the following:

```~
➜ pyenv install 2.7.14
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-2.7.14.tar.xz...
-> https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
Installing Python-2.7.14...
python-build: use readline from homebrew
Installing pip from https://bootstrap.pypa.io/get-pip.py...
error: failed to install pip via get-pip.py

BUILD FAILED (OS X 10.13.1 using python-build 20160602)

Inspect or clean up the working tree at /var/folders/y2/6bz4kq_s029_syhvswcw7w6w0000gn/T/python-build.20171204134242.61393
Results logged to /var/folders/y2/6bz4kq_s029_syhvswcw7w6w0000gn/T/python-build.20171204134242.61393.log

Last 10 log lines:
info = _mac_ver_xml()
File "/Users/nate/.pyenv/versions/2.7.14/lib/python2.7/platform.py", line 741, in _mac_ver_xml
pl = plistlib.readPlist(fn)
File "/Users/nate/.pyenv/versions/2.7.14/lib/python2.7/plistlib.py", line 78, in readPlist
rootObject = p.parse(pathOrFile)
File "/Users/nate/.pyenv/versions/2.7.14/lib/python2.7/plistlib.py", line 401, in parse
from xml.parsers.expat import ParserCreate
File "/Users/nate/.pyenv/versions/2.7.14/lib/python2.7/xml/parsers/expat.py", line 4, in
from pyexpat import *
ImportError: No module named pyexpat```

Nevermind on the above, I forgot that my LDFLAGS and CFLAGS were still set to get openssl to work.

For posterity, removing them from .zshrc allowed pyexpat to be found properly.

I got it working in _macOS High Sierra 10.13.1_ by installing openssl using brew install openssl, setting the CFLAGS to CFLAGS="-I$(brew --prefix openssl)/include" and LDFLAGS to LDFLAGS="-L$(brew --prefix openssl)/lib" and then following @heynairb comment to install pyenv using brew install pyenv --HEAD

Did what @sanghapriya said and it worked.

$ brew install openssl

Added to my .zshrc(I am using o-my-zsh)

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

and ran it again:

$ brew install pyenv --HEAD

After installing a new version, I still got the old version on my console, even after selecting it with pyenv global x.x.x

The solution was to add that to my .zshrc and reload it with source ~/.zshrc

export PATH="/Users/REPLACE_IT_WITH_YOUR_USERNAME/.pyenv:$PATH"
eval "$(pyenv init -)"

Here's my solution:
1) install readline xz openssl pyenv via homebrew ,
2) and if you've already installed these pkgs
brew upgrade openssl pyenv to the latest version
3) pyenv install your_version

I think this issue was fixed by https://github.com/pyenv/pyenv/pull/1025 which means that it's fixed in pyenv 1.2.0. I guess this issue can close?

@jenshnielsen I had this issue and just using latest versions of all mentioned packages worked.

This issue still happens https://github.com/pyenv/pyenv/issues/1066#issuecomment-357808697

@schinwang Solution works for me, upgrading brew pkgs resolved the issue.

I fixed this simply by updating pyenv: brew upgrade pyenv

I am seeing this failing again with python 3.7 betas. This seems to be due to https://bugs.python.org/issue32598 improving openssl configuration options.

For homebrew the following seems to work.

export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig/
pyenv install 3.7.0b2

Besides pyenv I also could not install ruby versions via rbenv. At this point I started looking at the system. I'd recently upgraded and used the migration assistant to move to a new machine.

  1. go to Applications and run Xcode. I had additional packages install
  2. run brew doctor. if any files in /usr/local/include show up you have 2 options. Either rename the directory to something else like include_old or remove the offending entries. I chose the first.

sudo mv /usr/local/include /usr/local/include_old
sudo mkdir /usr/local/include
sudo chown $YOU_USERNAME:admin /usr/local/include

afterward, I was able to install ruby and python versions

Hey guys, I just brew update pyenv and all works again.

I just wasted my entire morning fighting this issue on OSX Sierra 10.12.6 (not High Sierra). I was running pyenv installed from the bash script pyenv-installer. I tried just about every solution from installing openssl via brew, to uninstalling openssl and reinstalling, to downloading the headers and setting the include separately, to including CPPFLAGS as well as CFLAGS settings. Nothing worked!

The ONLY solution for me was to install pyenv via brew and delete the version installed via the pyenv-installer. I don't like installing programs in root folders and would have rather used the pyenv-installer since it puts things in my home dir but this was the only solution.

@cliff76 I had everything installed via homebrew but it kept failing.
I then realised that upgrading from Sierra to High Sierra and installing XCode 9.x might have broken something so I ran
xcode-select --install
and I got the popup to install/refresh all the command line tools.

After that it installed fine via pyenv :)

I had to run -
brew upgrade pyenv

This issue is being exacerbated to an insane degree by the fact that apparently Brew refuses to host openSSL 1.0.2t instead opting for 1.1.1 only; Python 2.7 can't function with 1.1.1 (apparently) and so I'm stuck at this error over and over again:

>pyenv install 2.7.10
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-2.7.10.tar.xz...
-> https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
Installing Python-2.7.10...
patching file ./Lib/site.py
python-build: use readline from homebrew
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

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


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

Inspect or clean up the working tree at /var/folders/qv/bywj26qd779_8jb49r151lrm0000gp/T/python-build.20191130235433.66266
Results logged to /var/folders/qv/bywj26qd779_8jb49r151lrm0000gp/T/python-build.20191130235433.66266.log

Last 10 log lines:
rm -f /usr/local/var/pyenv/versions/2.7.10/share/man/man1/python.1
(cd /usr/local/var/pyenv/versions/2.7.10/share/man/man1; ln -s python2.1 python.1)
if test "xno" != "xno"  ; then \
        case no in \
            upgrade) ensurepip="--upgrade" ;; \
            install|*) ensurepip="" ;; \
        esac; \
         ./python.exe -E -m ensurepip \
            $ensurepip --root=/ ; \
    fi

Same issue trying to install python 3.5.2 which is apparently compatible with openssl 1.1:
MacOs 10.15.2

CFLAGS="-I$(brew --prefix openssl)/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib" asdf install python 3.5.2
python-build 3.5.2 /Users/adamlancaster/.asdf/installs/python/3.5.2
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.5.2.tar.xz...
-> https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
Installing Python-3.5.2...
patching file Lib/venv/scripts/posix/activate.fish
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

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


BUILD FAILED (OS X 10.15.2 using python-build 1.2.16-2-g36fc10fb)

Inspect or clean up the working tree at /var/folders/gm/84m52gh16sx9g7l_gln_w77r0000gn/T/python-build.20200113113216.50262
Results logged to /var/folders/gm/84m52gh16sx9g7l_gln_w77r0000gn/T/python-build.20200113113216.50262.log

Last 10 log lines:
(cd /Users/adamlancaster/.asdf/installs/python/3.5.2/share/man/man1; ln -s python3.5.1 python3.1)
if test "xupgrade" != "xno"  ; then \
        case upgrade in \
            upgrade) ensurepip="--upgrade" ;; \
            install|*) ensurepip="" ;; \
        esac; \
         ./python.exe -E -m ensurepip \
            $ensurepip --root=/ ; \
    fi
Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS

Have tried re-installing openssl with brew nothing works

For those still having the same issue please try the steps below. None of the solutions above worked for me. It turns out I need to let pyenv install his own compatible openssl version

  1. brew uninstall openssl

  2. pyenv install 2.7.3

You will see then that it is installing a different version from the latest openssl version
Downloading openssl-1.0.2k.tar.gz... -> https://pyenv.github.io/pythons/6b3977c61f2aedf0f96367dcfb5c6e578cf37e7b8d913b4ecb6643c3cb88d8c0 Installing openssl-1.0.2k... ah Installed openssl-1.0.2k to /Users/joonkim/.pyenv/versions/2.7.3

Good luck!

@joony0123 's suggestion worked perfectly for me!

I managed to fix pyenv install for 3.7.X by reinstalling Xcode command line tools, but it still didn't work for 2.XX versions. I had openssl 1.1 installed through home-brew, but it didn't occur to me that the earlier versions of python weren't compatible with [email protected].

This is what I did to get everything working on my system. (adapted a bit of @joony0123's)

  1. brew uninstall openssl
  2. rm -rf ~/Library/Developer/CommandLineTools
  3. brew upgrade pyenv or brew install pyenv --HEAD as per @heynairb 's suggestion
  4. xcode-select --install

open up Xcode GUI and allow it to complete the installation of some more packages

finally,

  1. pyenv install X.X.X

Running on 10.15.2 Catalina

Hope this helps!

So finally I opened xcode Gui and it had some remaining packages to install

None of the solutions above seem to work with Python 2.6.0 (they do with > 2.7). Any ideas for this specific version?

@joony0123's solution worked for me, where every other mechanism (CPPFLAGS, LDFLAGS) did not. Uninstalling brew's openssl makes pyenv download a compatible openssl which it then installs in its private directory, and which it successfully builds python against. Then you can reinstall brew's openssl to restore the functionality of its dependents.

macOS Mojave 10.14.6, pyenv-1.12.16, Python-3.5.2 with openssl-1.0.2k.

For those still having the same issue please try the steps below. None of the solutions above worked for me. It turns out I need to let pyenv install his own compatible openssl version

brew uninstall openssl

pyenv install 2.7.3

You will see then that it is installing a different version from the latest openssl version
Downloading openssl-1.0.2k.tar.gz... -> https://pyenv.github.io/pythons/6b3977c61f2aedf0f96367dcfb5c6e578cf37e7b8d913b4ecb6643c3cb88d8c0 Installing openssl-1.0.2k... ah Installed openssl-1.0.2k to /Users/joonkim/.pyenv/versions/2.7.3

Good luck!

It worked for me,because if I ran brew install openssl, it installed [email protected] and it didn't work for me , still said no OpenSLl, and I use this method solve it ,and it installed openssl-1.0.2k, thanks

For those still having the same issue please try the steps below. None of the solutions above worked for me. It turns out I need to let pyenv install his own compatible openssl version
brew uninstall openssl
pyenv install 2.7.3
You will see then that it is installing a different version from the latest openssl version
Downloading openssl-1.0.2k.tar.gz... -> https://pyenv.github.io/pythons/6b3977c61f2aedf0f96367dcfb5c6e578cf37e7b8d913b4ecb6643c3cb88d8c0 Installing openssl-1.0.2k... ah Installed openssl-1.0.2k to /Users/joonkim/.pyenv/versions/2.7.3
Good luck!

It worked for me,because if I ran brew install openssl, it installed [email protected] and it didn't work for me , still said no OpenSLl, and I use this method solve it ,and it installed openssl-1.0.2k, thanks

you cannot use brew uninstall openssl command, since openssl is a dependency of pyenv
in #950 stream you can read the solution from "asmaier"
so you should use

'brew uninstall --ignore-dependencies [email protected]'

then you can install a python version older than 2.7.13 with its own old version of openssl

For reference, I didn't have to uninstall [email protected] from homebrew, but rather, install a more updated version of python 2.7. 2.7.12 did not work, but 2.7.13 worked.

After installing readline, xz, openssl and pyenv with homebrew I successfully installed python2 using this command:

CONFIGURE_OPTS="--with-openssl=/usr/local/opt/[email protected]" LDFLAGS="-L/usr/local/opt/[email protected]/lib" LD_RUN_PATH="/usr/local/opt/[email protected]/lib" CPPFLAGS="-I/usr/local/opt/[email protected]/include" CFLAGS="-I/usr/local/opt/[email protected]/include" pyenv install -v 2.7.13

It seems some versions of python2 won't work with openssl 1.1, which was deprecated from homebrew, even when explicitly set using env flags.

sudo PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v 2.7.6

it's seem use for me.

For someone encountering this error message when installing PyPy, this is a bug in PyPy 7.3.1: https://foss.heptapod.net/pypy/pypy/issues/3229

For someone encountering this error message when installing PyPy, this is a bug in PyPy 7.3.1: https://foss.heptapod.net/pypy/pypy/issues/3229

On macOS Catalina, I met this error message when installing PyPy 7.3.1. However, when changing to PyPy 7.3.0, errors disappear. Thanks!

Has anyone been able to install 2.5.6 on macOS using homebrew?

It seems the the script python-build can't detect sqlite nor openssl, I've tried with the command below but it doesn't work either:

CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" \
LD_RUN_PATH="$(brew --prefix openssl)/lib" \
CPPFLAGS="-I$(brew --prefix openssl)/include" \
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include -I$(brew --prefix readline)/include $CFLAGS -I$(brew --prefix openssl)/include -I$(brew --prefix sqlite)/include $CFLAGS" \
LDFLAGS="-L$(brew --prefix readline)/lib $LDFLAGS -L$(brew --prefix openssl)/lib $LDFLAGS -L$(brew --prefix sqlite)/lib $LDFLAGS" \
pyenv install 2.5.6
Was this page helpful?
0 / 5 - 0 ratings