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

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

Closed
uber1geek opened this issue Sep 29, 2017 · 42 comments

Comments

@uber1geek
Copy link

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

@BruceFrankWong
Copy link

BruceFrankWong 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
Copy link

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
Copy link
Author

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
Copy link
Author

or simply, brew install pyenv

@BruceFrankWong
Copy link

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

@jlott
Copy link

jlott commented Oct 5, 2017

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

@kryptek
Copy link

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!

@tshu-w
Copy link

tshu-w 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
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@sanghapriya
Copy link

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
Copy link

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

@chason-w
Copy link

chason-w 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
Copy link
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?

@Trefex
Copy link

Trefex commented Dec 16, 2017

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

@webknjaz
Copy link

This issue still happens #1066 (comment)

@etienne-bondot
Copy link

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

@maplethorpej
Copy link

I fixed this simply by updating pyenv: brew upgrade pyenv

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

@jalevin
Copy link

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
Copy link

marcwww commented Apr 23, 2018

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

@cliff76
Copy link

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
Copy link

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
Copy link

aramay commented Sep 11, 2018

I had to run -
brew upgrade pyenv

crcollins added a commit to crcollins/dragonfly that referenced this issue Apr 7, 2019
@Kezzsim
Copy link

Kezzsim commented Dec 1, 2019

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

@Adzz
Copy link

Adzz commented Jan 13, 2020

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

@joony0123
Copy link

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!

@satchelfrench
Copy link

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

@liriarte
Copy link

liriarte commented Feb 13, 2020

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

@shentonfreude
Copy link

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

@hsiunien
Copy link

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

@gobftald
Copy link

gobftald commented Apr 3, 2020

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

@zenbaku
Copy link

zenbaku commented Apr 16, 2020

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.

@lybwb
Copy link

lybwb commented Jun 29, 2020

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

it's seem use for me.

@bhy
Copy link

bhy commented Jul 2, 2020

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

@mathsyouth
Copy link

mathsyouth commented Jul 12, 2020

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!

@rraallvv
Copy link

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

@mcandre
Copy link

mcandre commented Mar 23, 2021

This problem is worsened by the pyenv build process identifying the OpenSSL version belatedly, partway into the compilation instead of at the very beginning.

Each debug iteration takes several minutes to fail, so the user has little information to work with.

As a workaround, I upgraded my Python from 3.4.3 to 3.9.2.

@native-api
Copy link
Member

@bradley
Copy link

bradley commented Jun 1, 2023

This is pretty over the top but what finally ended up working for me (M1), but I ended up adding this to my .zshrc. It does alias's calls to pyenv to add various apparently necessary configurations, and only does so in instances where the developer (me) is running an pyenv install. It will log a colorful warning message in such cases so that I dont forget this is happening or where to look if something starts to bug later.

Assumes you have the various listed packages installed via homebrew.

Here it is:

# Standard pyenv stuff
export PATH=/usr/local/bin:$PATH
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

# The pyenv alias function
function bradley_pyenv {
    if [[ $1 == "install" ]]; then
        print -P  "%F{cyan}Executing 'pyenv' as alias to 'bradley_pyenv'. See .zshrc for details!%f"

        # The following section configures various flags necessary to get pyenv
        # working with our OS. Please update as any of these details change, e.g.;
        # the OSX version or deployment target.

        # about readline
        LDFLAGS="-L$(brew --prefix readline)/lib $LDFLAGS"
        CPPFLAGS="-I$(brew --prefix readline)/include $CPPFLAGS"
        CFLAGS="-I$(brew --prefix readline)/include $CFLAGS"
        # about openssl
        LDFLAGS="-L$(brew --prefix openssl)/lib $LDFLAGS"
        CPPFLAGS="-I$(brew --prefix openssl)/include $CPPFLAGS"
        CFLAGS="-I$(brew --prefix openssl)/include $CFLAGS"
        # about tcl-tk
        LDFLAGS="-L$(brew --prefix tcl-tk)/lib $LDFLAGS"
        CPPFLAGS="-I$(brew --prefix tcl-tk)/include $CPPFLAGS"
        CFLAGS="-I$(brew --prefix tcl-tk)/include $CFLAGS"
        # about zlib
        LDFLAGS="-L$(brew --prefix zlib)/lib $LDFLAGS"
        CPPFLAGS="-I$(brew --prefix zlib)/include $CPPFLAGS"
        CFLAGS="-I$(brew --prefix zlib)/include $CFLAGS"
        # about bzip2
        LDFLAGS="-L$(brew --prefix bzip2)/lib $LDFLAGS"
        CPPFLAGS="-I$(brew --prefix bzip2)/include $CPPFLAGS"
        CFLAGS="-I$(brew --prefix bzip2)/include $CFLAGS"
        # about sqlite3
        LDFLAGS="-L$(brew --prefix sqlite3)/lib $LDFLAGS"
        CPPFLAGS="-I$(brew --prefix sqlite3)/include $CPPFLAGS"
        CFLAGS="-I$(brew --prefix sqlite3)/include $CFLAGS"

        CFLAGS="-I$(xcrun --show-sdk-path)/usr/include $CFLAGS"

        SDKROOT="$(xcrun --show-sdk-path)"

        MACOSX_DEPLOYMENT_TARGET=13.3

        PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA="openssl@3"

        PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2

        CC="$(brew --prefix gcc)/bin/gcc-13"

        # Execute custom pyenv command...
        command arch -x86_64 pyenv "$@"
    else
        # Execute as normal...
        command pyenv "$@"
    fi
}

alias pyenv=bradley_pyenv

@pyenv pyenv deleted a comment from natecox Jun 2, 2023
@pyenv pyenv deleted a comment from natecox Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests