Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't pip install packages in python 3.6 due to ssl error

Tags:

python

ssl

I'm working on a remote server. When I try to install anything with pip within my virtual environment I get an error:

(venv) [barta@bivoj program]$ pip install -r requirements.txt 
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting joblib==0.11 (from -r requirements.txt (line 1))
  Could not fetch URL https://pypi.python.org/simple/joblib/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping

Everything is working fine with python 2.7. Can I solve this problem by myself (I don't have root access) or do I need to contact the administrator?

First I had this problem when I installed python 3.6 in my home folder. I figured that the problem might be because it's in my home folder, so I asked for a clean install of python 3.6.

I considered changing the setup.py and install again in my home, as suggested here by Claudio:

pip3 installs inside virtual environment with python3.6 failing due to ssl module not available

but I didn't find any openssl folder. There is openssl in /usr/bin, but that is not a directory. I searched for the ssl.h file, but did not find it anywhere.

like image 726
Tom83B Avatar asked May 11 '17 18:05

Tom83B


3 Answers

Sounds like you've built python from source without libssl-dev present.

Run:

sudo apt-get install libssl-dev
sudo ./configure
sudo make altinstall
like image 185
Igonato Avatar answered Sep 22 '22 18:09

Igonato


This is how I did:

sudo apt-get install libssl-dev
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar -xvf Python-3.6.5.tgz
cd Python-3.6.5/

./configure
sudo make
sudo make install
like image 39
PhilKo Avatar answered Sep 22 '22 18:09

PhilKo


Tested in Ubuntu 16.04/18.04

In Python-3.6.4/Modules/Setup uncomment the following lines:

#   SSL=/usr/local/ssl
#   _ssl _ssl.c \
#       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#       -L$(SSL)/lib -lssl -lcrypto

Then recompile the package:

$ sudo ./configure --enable-optimizations
$ sudo make altinstall

Also make sure that libssl-dev is installed (this is the package for debian, anyway).

This also works for Python-3.7.x.

like image 37
inzem77 Avatar answered Sep 22 '22 18:09

inzem77