简体   繁体   English

由于ssl错误,无法在python 3.6中pip安装包

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

I'm working on a remote server. 我正在使用远程服务器。 When I try to install anything with pip within my virtual environment I get an error: 当我尝试在我的虚拟环境中使用pip安装任何东西时,我收到一个错误:

(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. 使用python 2.7一切正常。 Can I solve this problem by myself (I don't have root access) or do I need to contact the administrator? 我可以自己解决这个问题(我没有root权限)或者我是否需要联系管理员?

First I had this problem when I installed python 3.6 in my home folder. 首先,当我在我的主文件夹中安装python 3.6时,我遇到了这个问题。 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. 我想问题可能是因为它在我的主文件夹中,所以我要求干净安装python 3.6。

I considered changing the setup.py and install again in my home, as suggested here by Claudio: 我考虑更改setup.py并再次安装在我的家中,如Claudio所示:

pip3 installs inside virtual environment with python3.6 failing due to ssl module not available 由于ssl模块不可用,pip3安装在虚拟环境中,python3.6失败

but I didn't find any openssl folder. 但我没有找到任何openssl文件夹。 There is openssl in /usr/bin, but that is not a directory. / usr / bin中有openssl,但这不是目录。 I searched for the ssl.h file, but did not find it anywhere. 我搜索了ssl.h文件,但没有在任何地方找到它。

Sounds like you've built python from source without libssl-dev present. 听起来你已经在没有libssl-dev存在的情况下从源代码构建了python。

Run: 跑:

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

Tested in Ubuntu 16.04/18.04 在Ubuntu 16.04 / 18.04中测试过

In Python-3.6.4/Modules/Setup uncomment the following lines: 在Python-3.6.4 / Modules / Setup中取消注释以下行:

#   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). 还要确保安装了libssl-dev (这是debian的包,无论如何)。

This also works for Python-3.7.x. 这也适用于Python-3.7.x.

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 : 我得到了同样的错误,但实际上我使用最新版本的python2.7.13创建了python环境 ,这个python版本是通过安装的:

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

Then creating virtualenv : 然后创建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. 花了很多时间后,我发现一个名为libreadline6-dev库丢失了。 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. 并重复编译make安装步骤,如上所述,并再次创建虚拟环境。 Everything worked fine this time! 这次一切都很好!

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

如果这是Windows,则需要安装OpenSSL https://slproweb.com/products/Win32OpenSSL.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM