"ssl module in Python is not available" when installing package with pip3
Asked Answered
B

34

224

I've install Python 3.4 and Python 3.6 on my local machine successfully, but am unable to install packages with pip3.

When I execute pip3 install <package>, I get the following SSL related error:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting <package>
  Could not fetch URL https://pypi.python.org/simple/<package>/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement <package> (from versions: )
No matching distribution found for <package>

How can I fix my Python3.x install so that I can install packages with pip install <package>?

Bengt answered 26/12, 2016 at 8:27 Comment(4)
Did you explicitly install pip3 on your ubuntu with the command sudo apt-get install python3-pip ??Waldowaldon
Please try pip3 install --upgrade pip and see whether you get the same message or not.Limewater
@Limewater can't run that command due to the previous errorPhotoplay
I solved this with anaconda: conda install -c anaconda opensslEgotist
J
169

Step by step guide to install Python 3.6 and pip3 in Ubuntu

  1. Install the necessary packages for Python and ssl: $ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

  2. Download and unzip "Python-3.6.8.tar.xz" from https://www.python.org/ftp/python/ into your home directory.

  3. Open terminal in that directory and run: $ ./configure

  4. Build and install: $ make && sudo make install

  5. Install packages with: $ pip3 install package_name

Disclaimer: The above commands are not tested in Ubuntu 20.04 LTS.

Jackofalltrades answered 26/6, 2017 at 11:24 Comment(20)
Worked on "Raspbian GNU/Linux 9 (stretch)"Castigate
Thank you! I was going around in circles getting python3 working on Ubuntu 14.04 until I found this command list.Lecky
My Ubuntu saviour.Cannoneer
This worked for me. Many thanks. One thing I couldn't wrap my head around though, why not start with step 4 and only "make; make install" once?Gocart
Do not work for python 3.5.6 on Debian Testing/BusterRedound
Worked in Ubuntu Beaver. I was using python3.7 and pip 19, always with SSL problem.....Ringtail
Python 3.7 also needed libffi-dev to be installed on Debian Strech to compileSampling
Thanks! For me the key part that I missed and solved the problem was installing the package libssl-dev.Tillis
you shouldn't need to perform the make with sudo. I would also set up /usr/local subdirs to allow the make install to be without sudo as well, since it can be a PITA down the line regarding permissions when the directories are owned by root.Edda
I removed the older version (Python 3.7) from Mac and Download new latest version from https://www.python.org/downloads/. After that I create a new virtual env. Reinstall all packaegs. It helps to solve SSLError connect error.Achondroplasia
This did not work for me with python 3.7, it does work for python 3.6.8Nutshell
This will break down your system in Ubuntu > 20.04 cause "sudo make install" will try to overwrite default python version which is 3.8 in Ubuntu 20.04. Try "sudo make altinstall" insteadLuannaluanne
Worked for me on Ubuntu 20.04.1 LTS.Izabel
This solution is valid also for debian 10 bullseye, only the package libreadline-gplv2-dev was not found but the issue are solved even without this packageObumbrate
It solves almost all issues with Python 3.9 and Ubuntu 20.04.1, except _ctypes module, so i combined this answer with the following answerBetz
@user1330614 sudo make altinstall worked for me on Ubuntu 20.04 LTS, also. After this, packages installed just fine. Don't forget to update pip, itself.Fogg
libreadline-gplv2-dev hasn't been updated for a while. Probably should switch to libreadline-dev because the old version caused an interpreter freeze after failures in ctrl+r. See libreadline search resultsFraase
Ubuntu 20.04, python3.10 helps fixing SSLError when compiling from source. No need of make install, can be used from custom location.Benson
This is working in Ubuntu 20.04.1 LTS.Ferde
I really don't want X11.Ardath
R
118

If you are on Windows and use anaconda this worked for me:

I tried a lot of other solutions which did not work (Environment PATH Variable changes ...)

The problem can be caused by DLLs in the Windows\System32 folder (e.g. libcrypto-1_1-x64.dll or libssl-1_1-x64.dll or others) placed there by other software.

The fix was installing openSSL from https://slproweb.com/products/Win32OpenSSL.html which replaces the dlls by more recent versions.

Riposte answered 28/2, 2019 at 18:34 Comment(17)
Do I need to just install it or do something else?Tjader
I just installed it. In the list of the programs installed on my system I have three versions of OpenSSL (two 64 bit versions and one 32 bit version, although I am on a 64 bit system). I am not aware having installed all of them, so I left them there.Riposte
Thank you, it worked for me. System: Windows 10, Anaconda, Python 3.7Convent
This was the most straight forward solution I have found after much searching. Pip was not working due to OpenSSL error. Spyder also crashed at launch due to a "cannot import name 'HTTPSHandler' from 'urllib.request'" error. This was isolated to windows 10 python 3 for me. Commenting to hopefully help link the solution for people googling, most top results were old and complex solutions.Salgado
Excellent Solution - make sure to overwrite the DLL's in the SYSTEM folder ! :-)Demogorgon
If you are on Windows and use Anaconda just use Anaconda Prompt instead of cmd to run "pip install". No additional DLL/SSL change will be required.Silures
@Silures - Thanks a lot. It helped me.Timbuktu
Literally only thing that has worked. Thank you so much!Carnotite
I was about to break my computer, used pycharm on a lot of machines and OSs but on this new windows one i installed anaconda and it seems it broke pip. I was browsing for like 2 hours, thank you so much mate. <3Cockaleekie
If this solution is not working for you, check if you installed the OpenSSL version matching your Python version (i.e. 32 vs. 64). It worked for me.Allhallowtide
Helped me as well. Wonder why Windows does not automatically update this.Floeter
Great solution! Works on the 3.6mb minimal package on the website given, overwrite in the Windows system folder and pip will work!Doerrer
Your answer fix the problem on my system!!! Thanks!Motta
you, are a hero. Thank you so very much !Ethnography
Shit man, been struggling with this issue for such a long time. You beautiful human beingLyn
@Silures Wrong. It shows the same SSL error for meNahshu
Conda promt didn't help but openSSL solved everything!Pathology
L
86

If you are on Red Hat/CentOS:

# To allow for building python ssl libs
yum install openssl-devel
# Download the source of *any* python version
cd /usr/src
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
tar xf Python-3.6.2.tar.xz 
cd Python-3.6.2

# Configure the build w/ your installed libraries
./configure

# Install into /usr/local/bin/python3.6, don't overwrite global python bin
make altinstall
Lava answered 31/7, 2017 at 13:56 Comment(8)
worked for python 2.7 as well. just add make and make altinstallScepter
If you need virtualenv, you have to run sudo /usr/local/bin/pip3.7 install virtualenv. Thank you for this answer!Nephrolith
excellent, I was having trouble installing python 2.7.13 for a legacy docker image and needed openssl-devel to run python2.7 get-pip.pyLighterage
installed openssl-devel, ran again configure and make, make install. Worked just great!Derrick
install openssl-devel and then reconfigure/rebuild/reinstall python fixed the problem for me.Disputation
Isn't this missing the make command? (And ./configure --enable-optimizations is recommended, I believe.)Caro
This did NOT work for me on CentOS 7 installing Python-3.10. Here's a method that DID work: https://mcmap.net/q/82815/-building-python-and-openssl-from-source-but-ssl-module-fails (symlinking openssl to recreate the paths that python looks for)Corporator
For optimizations option --enable-optimizations in CentOS 7 see here: https://mcmap.net/q/81002/-how-to-succesfully-compile-python-3-x. And for CentOS 7 compilation: https://mcmap.net/q/81001/-how-to-fix-quot-ssl-module-in-python-is-not-available-quot-in-centos.Seaway
R
52

I had a similar problem on OSX 10.11 due to installing memcached which installed python 3.7 on top of 3.6.

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Spent hours on unlinking openssl, reinstalling, changing paths.. and nothing helped. Changing openssl version back from to older version did the trick:

brew switch openssl 1.0.2e

I did not see this suggestion anywhere in internet. Hope it serves someone.

Rowlandson answered 4/2, 2020 at 12:8 Comment(8)
I had the same issue with MacOS Catalina 10.5.4 (Beta), now it works. Thank you!Vacationist
For me it was brew switch openssl 1.0.2s. But that was it. You've saved me, thanks!Inverse
Trying this but it keeps telling me openssl does not have a version "1.0.2e" in the Cellar. openssl does not have a version "1.0.2s" in the Cellar.Doctrine
Antonio, James: whatever older version you have. My Cellar had 1.0.2e so I used this. I'm glad it helped.Rowlandson
Thank you so much! For me, your solution of switching to an older version of openssl worked: brew switch openssl 1.0.2t I'm on Mac OS Catalina 10.15.3. Hope it helps.Controller
I also had this problem and switched to 1.0.2s, and while it's great to have the fix, seems not great to have to roll back to older versions of SSLOstwald
On OSX High Sierra, brew switch openssl 1.0.2o_2 works for meDumyat
Trying this it get error that openssl doesn't have a version 1.0.2s. and It looks like there is no any old version of openssl in my mac.Urine
F
40

In Ubuntu, this can help:

cd Python-3.6.2
./configure --with-ssl
make
sudo make install
Farmergeneral answered 11/1, 2019 at 14:34 Comment(7)
Why do we actually have to build python from source for this? is there not a solution that works with standard python distributions? I would kind of naively hope adding this module would be possible without overriding the python binary, which we don't always easily know the corresponding source location for, on a live system not freshly installed.Perverted
Tried this, didn't change anythingSingapore
I get a warning saying this option is not recognizedBed
I had to append several 'sudo' to those commands, but they worked where other answers failed!Siloxane
Thanks a lot this helped.Mump
According to ./configure --help for Python 3.9.1, the option is now called --with-openssl, and it should point to a directory. In Ubuntu, adding --with-openssl=$LD_LIBRARY_PATH will doMontagna
which directory it should point to ? I am isside the virtual environment.Vendible
O
33

Agree with the answer by mastaBlasta. Worked for me. I encountered the same problem as the topic description.

Environment: MacOS Sierra. And I use Homebrew.

My solution:

  1. Reinstall openssl by brew uninstall openssl; brew install openssl
  2. According to the hints given by Homebrew, do the following:

    echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
    export LDFLAGS="-L/usr/local/opt/openssl/lib"
    export CPPFLAGS="-I/usr/local/opt/openssl/include"
    
Operculum answered 24/5, 2018 at 11:45 Comment(2)
Thanks, the trick is brew uninstall openssl, brew install openssl. I tried brew reinstall openssl which had no effect. But the uninstall/install works!Bria
had to run brew uninstall --ignore-dependencies opensslBursa
B
23

I had the same issue with python3.8.5 installation on Debian9. I have done a build, but when I have tried to download some modules, pip3.8 issued following error:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

I have searched for the root of my problem and found out that there is a system dependent portion of the python build which is called by system independent one. In case of missing ssl you just needed to open python terminal and check whether is _ssl present:

>>> help('modules')
.
.
_sre                enum                pwd                 wave
_ssl                errno               py_compile          weakref
_stat               faulthandler        pyclbr              webbrowser
.
.

If not your system dependent ssl module part is missing. You can check it also by listing content of <python_installation_root>/lib/python3.8/lib-dynload:

>ls ./lib/python3.8/lib-dynload | grep ssl
_ssl.cpython-38-x86_64-linux-gnu.so

The problem was caused as written by PengShaw by missing libssl-dev during the build. Therefore you have to follow the recommended python installation flow. First install prerequisites and then build and install the python. Installation without devel versions of libs resulted in my case in the missing system dependent part. In this case _ssl.

Note that the devel lib name differs for Debian and CentOS, therefore check whether the installation hints posted on net are suitable for your specific Linux system type:

For Debian:
sudo apt install -y libbz2-dev libffi-dev libssl-dev
./configure --enable-optimizations
make
make altinstall


For CentOS:
sudo yum -y install bzip2-devel libffi-devel openssl-devel
./configure --enable-optimizations
make
make altinstall

It is for sure a good idea to list configuration options prior the configuration and evtl. use some additional options:

./configure --help

Last but not least in case you use --prefix for a non-default installation location, remember to add your <python_installation_root>/lib to your LD_LIBRARY_PATH .

Brokenhearted answered 17/9, 2020 at 12:35 Comment(3)
Excellent. Helping us understand how to debug the problem, understand the source and fix it properly.Alemanni
Good explanation for why I still get the error even though I have installed ssl module after installing Python 3.9.Buzzell
On CentOS I needed to further sym-link openssl11 in /usr/local/openssl11 to match what python installer was looking for, as explained here: https://mcmap.net/q/82815/-building-python-and-openssl-from-source-but-ssl-module-failsCorporator
N
12

If you are on Windows and use Anaconda you can try running "pip install ..." command in Anaconda Prompt instead of cmd.exe, as user willliu1995 suggests here. This was the fastest solution for me, that does not require installation of additional components.

Naylor answered 2/5, 2019 at 10:28 Comment(0)
B
10

The problem probably caused by library missing.

Before you install python 3.6, make sure you install all the libraries required for python.

$ sudo apt-get install build-essential checkinstall 
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

More information in How to Install Python 3.6.0 on Ubuntu & LinuxMint

Biceps answered 19/2, 2017 at 14:28 Comment(0)
D
9

Downgrading openssl worked for me,

brew switch openssl 1.0.2s
Drive answered 25/5, 2020 at 8:37 Comment(0)
H
8

If you are on OSX and have compiled python from source:

Install openssl using brew brew install openssl

Make sure to follow the instructions brew gives you about setting your CPPFLAGS and LDFLAGS. In my case I am using the [email protected] brew formula and I need these 3 settings for the python build process to correctly link to my SSL library:

export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"

Assuming the library is installed at that location.

Hiles answered 28/2, 2018 at 17:2 Comment(3)
still the same issueGracia
Try reinstalling pipHiles
@GauravPaliwal, @mastaBlasta: For me, switching to an older version of openssl worked: brew switch openssl 1.0.2t I'm on Mac OS Catalina 10.15.3. Hope it helps.Controller
C
7

I tried A LOT of ways to solve this problem and none solved. I'm currently on Windows 10.

The only thing that worked was:

  • Uninstall Anaconda
  • Uninstall Python (i was using version 3.7.3)
  • Install Python again (remember to check the option to automatically add to PATH)

Then I've downloaded all the libs I needed using PIP... and worked!

Don't know why, or if the problem was somehow related to Anaconda.

Comptom answered 2/7, 2019 at 18:26 Comment(0)
R
7

for osx brew users

my issue appeared related to my python installation and was quickly resolved by re-installing python3 and pip. i think it started misbehaving after an OS update but who knows (at this time I am on Mac OS 10.14.6)

brew reinstall python3 --force
# setup pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
# installa pkg successfully 
pip install pandas
Resent answered 17/2, 2020 at 15:31 Comment(1)
Thankyou for this answer! In my case, the problems started after updating to Catalina (10.15.3), and I found that your first step brew reinstall python3 --force was sufficient: pip worked again after that, I didn’t need to reinstall pip.Talaria
H
6

I encountered the same problem on windows 10. My very specific issue is due to my installation of Anaconda. I installed Anaconda and under the path Path/to/Anaconda3/, there comes the python.exe. Thus, I didn't install python at all because Anaconda includes python. When using pip to install packages, I found the same error report, pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available..

The solution was the following:

1) you can download python again on the official website;

2) Navigate to the directory where "Python 3.7 (64-bit).lnk"is located

3) import ssl and exit()

4) type in cmd, "Python 3.7 (64-bit).lnk" -m pip install tensorflow for instance.

Here, you're all set.

Helmut answered 26/2, 2019 at 23:8 Comment(2)
Not a fix, but definitely gets the job done. At least helps you install missing deps. What I realized on my local machine, is that I had conflicting entries in my PATH variable for python (ie. Anaconda 2.7 64-bit and Python 3.7 32-bit)Mangan
Also to improve upon this answer, you could store the absolute path in a variable and run it as: cmd /c $py .\main.py (Powershell) or cmd /c %py% .\main.py (Dos). This will run it in your existing shell and can be scriptedMangan
G
6

You can do either of these two:

  1. While installing Anaconda, select the option to add Anaconda to the path.

or

  1. Find these (complete) paths from your installation folder of Anaconda and add them to the environment variable :

\Anaconda

\Anaconda\Library\mingw-w64\bin

\Anaconda\Library\usr\bin

\Anaconda\Library\bin

\Anaconda\Scripts

\anaconda\Library

\anaconda\condabin

Add the above paths to the "Path" system variable and it should show the error no more :)

Gabar answered 22/10, 2019 at 18:12 Comment(1)
One alternative is to use the specific 'anaconda prompt' which has these environment variables set up correctly.Haarlem
O
5

The ssl module is a TLS/SSL wrapper for accessing Operation Sytem (OS) socket (Lib/ssl.py). So when ssl module is not available, chances are that you either don't have OS OpenSSL libraries installed, or those libraries were not found when you install Python. Let assume it is a later case (aka: you already have OpenSSL installed, but they are not correctly linked when installing Python).

I will also assume you are installing from source. If you are installing from binary (ie: Window .exe file), or package (Mac .dmg, or Ubuntu apt), there is not much you can do with the installing process.

During the step of configuring your python installation, you need to specify where the OS OpenSSL will be used for linking:

# python 3.8 beta
./configure --with-openssl="your_OpenSSL root"

So where will you find your installed OpenSSL directory?

# ubuntu 
locate ssl.h | grep '/openssl/ssl.h'

/home/user/.linuxbrew/Cellar/openssl/1.0.2r/include/openssl/ssl.h
/home/user/envs/py37/include/openssl/ssl.h
/home/user/miniconda3/envs/py38b3/include/openssl/ssl.h
/home/user/miniconda3/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.0.2s-h7b6447c_0/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1b-h7b6447c_1/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1c-h7b6447c_1/include/openssl/ssl.h
/usr/include/openssl/ssl.h

Your system may be different than mine, but as you see here I have many different installed openssl libraries. As the time of this writing, python 3.8 expects openssl 1.0.2 or 1.1:

Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().

So you would need to verify which of those installed libraries that you can use for linking, for example

/usr/bin/openssl version

OpenSSL 1.0.2g  1 Mar 2016
./configure --with-openssl="/usr"
make && make install

You may need to try a few, or install a new, to find the library that would work for your Python and your OS.

Oaf answered 2/8, 2019 at 20:55 Comment(0)
A
2

I was having the same issue and was able to resolve with the following steps:

sudo yum install -y libffi-devel
sudo yum install openssl-devel
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
sudo tar xf Python-3.7.1.tar.xz
cd Python-3.7.1
sudo ./configure --enable-optimizations
# Install into /usr/local/bin/python3.7, don't overwrite global python bin
sudo make altinstall

depending on perms, you may not need sudo.

Results:
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1

should now be able to run

python3.7 -V 

and

pip3.7 -V

When installing packages:

pip3.7 install pandas

or depending on perms, you can also add the --user flag like so:

pip3.7 install pandas --user
Aedile answered 22/10, 2018 at 21:1 Comment(0)
R
2

In my case with using Mac, I deleted /Applications/Python 3.7. because I already had Python3.7 by brew install python3 .

But it was a trigger of the message

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

What I did in my situation

  1. I downloaded macOS 64-bit installer again, and installed.
  2. Double click /Applications/Python3.6/Install Certificates.command and /Applications/Python3.6/Update Shell Profile.command.
  3. Reboot mac
  4. And I am not sure but possibly contributed to succeed is pip.conf. See pip install fails.
Religion answered 9/1, 2020 at 0:4 Comment(0)
F
2

I finally solve this issue. These are the detail of my env:
Version of Python to install: 3.6.8
OS: Ubuntu 16.04.6 LTS
Root access: No

Some people suggest to install libssl-dev, but it did not work for me. I follow this link and I fixed it!
In short, I download, extract, build, and install OpenSSL (openssl-1.1.1b.tar.gz). Then, I modify .bashrc file follow this link.
Next, I download and extract Python-3.6.8.tgz. I edit Modules/Setup.dist to modify SSL path (lines around #211). I did ./configure --prefix=$HOME/opt/python-3.6.8, make and make install. Last, I modify my .bashrc. Notice that I do not include --enable-optimizations in ./configure.

Fail answered 28/4, 2020 at 11:18 Comment(0)
S
2

I was able to fix this by updating the python version in this file. pyenv: version `3.6.5' is not installed (set by /Users/taruntarun/.python-version) Though i had the latest version installed, my command was still using old version 3.6.5

Moving to version 3.7.3

Swetlana answered 27/7, 2020 at 15:36 Comment(0)
L
2

Termux

This worked because i didnt have an existing openssl version installed.

pkg install openssl-tool
Lavernalaverne answered 30/4, 2022 at 16:53 Comment(0)
S
1

If you are on OSX and in case the other solutions didn't work for you (just like me).

You can try uninstalling python3 and upgrade pip3

brew uninstall --ignore-dependencies python3
pip3 install --upgrade pip   

This worked for me ;)

Simplism answered 21/2, 2020 at 15:49 Comment(0)
E
1

(NOT on Windows!)

This made me tear my hair out for a week, so I hope this will help someone

I tried everything short of re-installing Anaconda and/or Jupyter.

Setup

  • AWS Linux
  • Manually installed Anaconda 3-5.3.0
  • Python3 (3.7) was running inside anaconda (ie, ./anaconda3/bin/python)
  • there was also /usr/bin/python and /usr/bin/python3 (but these were not being used as most of the work was done in Jupyter's terminal)

Fix

In Jupyter's terminal:

cp /usr/lib64/libssl.so.10 ./anaconda3/lib/libssl.so.1.0.0

cp /usr/lib64/libcrypto.so.10 ./anaconda3/lib/libcrypto.so.1.0.0

What triggered this?

So, this was all working until I tried to do a conda install conda-forge

I'm not sure what happened, but conda must have updated openssl on the box (I'm guessing) so after this, everything broke.

Basically, unknown to me, conda had updated openssl, but somehow deleted the old libraries and replaced it with libssl.so.1.1 and libcrypto.so.1.1.

Python3, I guess, was compiled to look for libssl.so.1.0.0

In the end, the key to diagnosis was this:

python -c "import ssl; print (ssl.OPENSSL_VERSION)"

gave the clue library "libssl.so.1.0.0" not found

The huge assumption I made is that the yum version of ssl is the same as the conda version, so just renaming the shared object might work, and it did.

My other solution was to re-compile python, re-install anaconda, etc, but in the end I'm glad I didn't need to.

Hope this helps you guys out.

Expatriate answered 10/7, 2020 at 6:48 Comment(0)
D
1

In the case of using pyenv to manage python installations on Mac OS Catalina, I had to install openssl with brew first and then after that run pyenv install 3.7.8 which seemed to build the python installation using the openssl from homebrew (it even said as such in the installation output). Then pyenv global 3.7.8 and I was away.

Democracy answered 23/7, 2020 at 14:30 Comment(0)
D
1

When installing Python 3.11 on AWS Linux, you need to:

sudo yum remove openssl-devel
sudo yum install openssl11-1.1.1g openssl11-libs-1.1.1g openssl11-devel-1.1.1g

You can then just run:

./configure --enable-optimizations
sudo make altinstall

Answer from https://github.com/actions/setup-python/issues/93 and verified working as of January 2024

Depersonalization answered 23/1 at 15:9 Comment(0)
M
0

On macos, configure python 3.8.1 with the command below will solve the problem, i think it would also work on Linux.

./configure --enable-optimizations --with-openssl=/usr/local/opt/[email protected]/

change the dir parameter based on your system.

Menology answered 29/1, 2020 at 13:25 Comment(0)
K
0

I've made some PATH changes to mimic part of the Anaconda Powershell Prompt $env:PATH

C:\Users\merheb\Miniconda3;C:\Users\merheb\Miniconda3\Library\mingw-w64\bin;C:\Users\merheb\Miniconda3\Library\usr\bin;C:\Users\merheb\Miniconda3\Library\bin;C:\Users\merheb\Miniconda3\Scripts;C:\Users\merheb\Miniconda3\bin;C:\Users\merheb\Miniconda3\condabin;

enter image description here

And It worked for me.

Krafftebing answered 19/7, 2022 at 19:40 Comment(0)
W
0

Building from source was what worked for me on Ubuntu 22.10:

Install OpenSSL manually, tested here with OpenSSL 1.1.1s, extracted then ran:

./config --prefix='/opt/openssl' --openssldir='/opt/ssl'
make
make install

Then with your older Python 3 version (here Python-3.8.16) run:

export LD_RUN_PATH='/opt/openssl/lib'
export CC='gcc-12'  # sudo apt install gcc-12
./configure --enable-optimizations \
            --with-openssl='/opt/openssl' \
            --prefix='/opt/python/3.8' -C
make
make install

Test with:

/opt/python/3.8/bin/python3 -c 'import ssl; print(ssl.OPENSSL_VERSION)'
OpenSSL 1.1.1s  1 Nov 2022
Winfield answered 16/1, 2023 at 21:54 Comment(0)
Z
0

I have this issue with centos 7 and python 3.6. None of the answers solves it and I finally figured out how to fix it.

First, install openssl from source code by following this link:

install openssl

After that, ssl header file "openssl/ssl.h" is in path:

/usr/local/openssl/include

ssl lib file is in path;

/usr/local/openssl/lib

Now compile python from source code. Before compile it, go to setup.py, locate function detect_modules(), search for 'ssl'.

Add ssl include file path to the following code:

        search_for_ssl_incs_in = [
                              '/usr/local/openssl/include'
                             ]

For lib file, there is trick here.

the code is searching for ssl lib file firstly from some standard system paths:

lib_dirs: ['/usr/local/lib', '/lib64', '/usr/lib64', '/lib', '/usr/lib']

If any of these folder contains ssl lib file, then it will return an empty path so the compile will skip ssl. I don't know the logic here but I just removed ssl lib file from these paths. In my host, there is libssl.a in /lib, so move it to an subfolder.

Then assign ssl lib path in setup.py:

        ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
                                     [
                                      '/usr/local/openssl/lib'
                                     ] )

Compile python:

./configure
make
make install
Zeena answered 6/5, 2023 at 2:48 Comment(0)
H
-1

I was having the same problem for the last two days and only have fixed it right now.

I had tried to use --trust-host option with the DigiCert_High_Assurance_EV_Root_CA.pem did not work, I couldn't install the ssl module (It tells it cannot be installed for python versions greater than 2.6), setting the $PIP_CERT variable didn't fix it either and I had libssl1.0.2 and libssl1.0.0 installed. Also worth mentioning I didn't had a ~/.pip/pip.conf file, and creating it didn't solve the bug either.

What finally solved it, was installing python3.6 with make again. Download the Python-3.6.0.tgz from the website, run configure then make, make test and make install. Hope it works for you.

Hendrika answered 27/12, 2016 at 19:50 Comment(1)
Sorry but had to downvote due to this simply stating to repeatthe same steps that caused this error. I don't know how you would expect to run the same commands on the same python source and get different results!Kraut
C
-1

The python documentation is actually very clear, and following the instructions did the job whereas other answers I found here were not fixing this issue.

  1. first, install python 3.x.x from source using, for example with version 3.6.2 https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

  2. make sure you have openssl installed by running brew install openssl

  3. unzip it and move to the python directory: tar xvzf Python-3.6.2.tar.xz && cd Python-3.6.2

  4. then if the python version is < 3.7, run

CPPFLAGS="-I$(brew --prefix openssl)/include" \ LDFLAGS="-L$(brew --prefix openssl)/lib" \ ./configure --with-pydebug 5. finallly, run make -s -j2 (-s is the silent flag, -j2 tells your machine to use 2 jobs)

Commoner answered 10/9, 2018 at 13:50 Comment(1)
j is the mnemonic for “jobs” which is the number of processes ran in parallel run the build. As for the s flag, it still outputs warnings, but without the additional noise of info/debug levels. These flags are used in the python docs instructions.Commoner
O
-1

I had the same issue trying to install python3.7 on an ubuntu14.04 machine. The issue was that I had some custom folders in my PKG_CONFIG_PATH and in my LD_LIBRARY_PATH, which prevented the python build process to find the system openssl libraries.

so try to clear them and see what happens:

export PKG_CONFIG_PATH=""
export LD_LIBRARY_PATH=""
Oily answered 27/9, 2018 at 13:12 Comment(1)
This would actually ruin someone's day if they have useful stuff in those environment variablesPerverted
P
-1

Ok the latest answer to this, as of now don't use Python 3.8, use only 3.7 or less , because of most of the libraries fail to install with the above error

Pekoe answered 10/3, 2020 at 19:29 Comment(2)
As far as I know python uses underlying packages of the operating system. Things like gcc, openssl and zlib. So it is important to install these prerequisites before compiling python especially when used on linux.Kammerer
@surfer190 I use windows, but what you said might be true for both I guessPekoe
E
-5

If in windows and using anaconda, than I solved it by first,

conda activate
pip install <lib>

This worked for me.

Ecotone answered 21/1, 2021 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.