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

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

Open
uber1geek opened this Issue Sep 29, 2017 · 28 comments

Comments

Projects
None yet
@uber1geek

uber1geek commented Sep 29, 2017

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

@BruceFrankWang

This comment has been minimized.

Show comment
Hide comment
@BruceFrankWang

BruceFrankWang Sep 30, 2017

@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

BruceFrankWang commented Sep 30, 2017

@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

@natecox

This comment has been minimized.

Show comment
Hide comment
@natecox

natecox Oct 2, 2017

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?

natecox commented Oct 2, 2017

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?

@uber1geek

This comment has been minimized.

Show comment
Hide comment
@uber1geek

uber1geek Oct 2, 2017

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

uber1geek commented Oct 2, 2017

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

@uber1geek

This comment has been minimized.

Show comment
Hide comment
@uber1geek

uber1geek Oct 2, 2017

or simply, brew install pyenv

uber1geek commented Oct 2, 2017

or simply, brew install pyenv

@BruceFrankWang

This comment has been minimized.

Show comment
Hide comment
@BruceFrankWang

BruceFrankWang Oct 3, 2017

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

BruceFrankWang commented Oct 3, 2017

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

@jlott

This comment has been minimized.

Show comment
Hide comment
@jlott

jlott Oct 5, 2017

This can be solved pretty easily without installing homebrew. See my comment here #950 (comment)

jlott commented Oct 5, 2017

This can be solved pretty easily without installing homebrew. See my comment here #950 (comment)

@kryptek

This comment has been minimized.

Show comment
Hide comment
@kryptek

kryptek Oct 12, 2017

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!

kryptek commented Oct 12, 2017

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!

@Voleking

This comment has been minimized.

Show comment
Hide comment
@Voleking

Voleking Oct 19, 2017

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.

Voleking commented Oct 19, 2017

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.

@wdeer

This comment has been minimized.

Show comment
Hide comment
@wdeer

wdeer Oct 19, 2017

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'

wdeer commented Oct 19, 2017

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'
@justinfinkle

This comment has been minimized.

Show comment
Hide comment
@justinfinkle

justinfinkle Oct 26, 2017

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.

justinfinkle commented Oct 26, 2017

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.

@mpasternak

This comment has been minimized.

Show comment
Hide comment
@mpasternak

mpasternak Nov 17, 2017

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

mpasternak commented Nov 17, 2017

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

@heynairb

This comment has been minimized.

Show comment
Hide comment
@heynairb

heynairb Dec 4, 2017

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 commented Dec 4, 2017

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

@natecox

This comment has been minimized.

Show comment
Hide comment
@natecox

natecox Dec 4, 2017

@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 <module>
    from pyexpat import *
ImportError: No module named pyexpat```

natecox commented Dec 4, 2017

@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 <module>
    from pyexpat import *
ImportError: No module named pyexpat```
@natecox

This comment has been minimized.

Show comment
Hide comment
@natecox

natecox Dec 5, 2017

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.

natecox commented Dec 5, 2017

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.

@sanghapriya

This comment has been minimized.

Show comment
Hide comment
@sanghapriya

sanghapriya Dec 5, 2017

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

sanghapriya commented Dec 5, 2017

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

@brunojppb

This comment has been minimized.

Show comment
Hide comment
@brunojppb

brunojppb Dec 6, 2017

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 -)"

brunojppb commented Dec 6, 2017

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 -)"
@schinwang

This comment has been minimized.

Show comment
Hide comment
@schinwang

schinwang Dec 15, 2017

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

schinwang commented Dec 15, 2017

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
@jenshnielsen

This comment has been minimized.

Show comment
Hide comment
@jenshnielsen

jenshnielsen Dec 15, 2017

Contributor

I think this issue was fixed by #1025 which means that it's fixed in pyenv 1.2.0. I guess this issue can close?

Contributor

jenshnielsen commented Dec 15, 2017

I think this issue was fixed by #1025 which means that it's fixed in pyenv 1.2.0. I guess this issue can close?

@Trefex

This comment has been minimized.

Show comment
Hide comment
@Trefex

Trefex Dec 16, 2017

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

Trefex commented Dec 16, 2017

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

@webknjaz

This comment has been minimized.

Show comment
Hide comment
@webknjaz

webknjaz Jan 15, 2018

This issue still happens #1066 (comment)

webknjaz commented Jan 15, 2018

This issue still happens #1066 (comment)

@etienne-bondot

This comment has been minimized.

Show comment
Hide comment
@etienne-bondot

etienne-bondot Mar 8, 2018

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

etienne-bondot commented Mar 8, 2018

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

@maplethorpej

This comment has been minimized.

Show comment
Hide comment
@maplethorpej

maplethorpej Mar 10, 2018

I fixed this simply by updating pyenv: brew upgrade pyenv

maplethorpej commented Mar 10, 2018

I fixed this simply by updating pyenv: brew upgrade pyenv

@jenshnielsen

This comment has been minimized.

Show comment
Hide comment
@jenshnielsen

jenshnielsen Mar 12, 2018

Contributor

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
Contributor

jenshnielsen commented Mar 12, 2018

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
@jalevin

This comment has been minimized.

Show comment
Hide comment
@jalevin

jalevin Apr 19, 2018

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

jalevin commented Apr 19, 2018

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

@marcwww

This comment has been minimized.

Show comment
Hide comment
@marcwww

marcwww Apr 23, 2018

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

marcwww commented Apr 23, 2018

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

@cliff76

This comment has been minimized.

Show comment
Hide comment
@cliff76

cliff76 Jul 9, 2018

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 commented Jul 9, 2018

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.

@ubidefeo

This comment has been minimized.

Show comment
Hide comment
@ubidefeo

ubidefeo Jul 23, 2018

@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 :)

ubidefeo commented Jul 23, 2018

@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 :)

@aramay

This comment has been minimized.

Show comment
Hide comment
@aramay

aramay Sep 11, 2018

I had to run -
brew upgrade pyenv

aramay commented Sep 11, 2018

I had to run -
brew upgrade pyenv

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