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

泪湿孤枕 提交于 2020-05-12 12:06:08

问题


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.


回答1:


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

Run:

sudo apt-get install libssl-dev
sudo ./configure
sudo make altinstall



回答2:


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.




回答3:


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



回答4:


I got same error but actually I created python environment using a latest version of python2.7.13 and this python version was installed via source:

./configure --prefix /usr/bin/python2.7.13
make altinstall

Then creating virtualenv:

virtualenv --python=/usr/bin/python2.7.13/bin/python2.7 py2.7.13env

After spending a lot of time I found that one library named libreadline6-dev was missing. So installed it:

sudo apt-get install libreadline6-dev

and repeated compile and make install steps as mentioned above and again created the virtual env. Everything worked fine this time!




回答5:


If this is Windows, you need to install OpenSSL https://slproweb.com/products/Win32OpenSSL.html



来源:https://stackoverflow.com/questions/43923085/cant-pip-install-packages-in-python-3-6-due-to-ssl-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!