" Python中的ssl模块不可用"

时间:2018-03-04 11:15:45

标签: python pip

仍然在我的教程中推进学习python,我被告知要做

sudo -H pip install requests

我得到以下内容:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting requests
  Could not fetch URL https://pypi.python.org/simple/requests/: 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 requests (from versions: )
No matching distribution found for requests

有人知道我需要做些什么才能解决这个问题吗?

非常感谢

6 个答案:

答案 0 :(得分:5)

自从新安装Python 3.6以来,我使用Linux发行版并面对这个问题。 我尝试了几个解决方案,最后解决了这个问题。我遵循的步骤如下。

像发行版一样在Debian上播放

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

将目录更改为Python3.6位置

cd /path/to/Python3.6/Module/

在模块目录中,使用首选文本编辑器打开Setup文件

vi Setup

搜索SSL并取消注释相关行。

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

保存文件并在Python包的根文件夹中,运行以下命令。

make
sudo make install

最后,运行pip3来安装所需的模块。

答案 1 :(得分:1)

使用./configure运行--enable-optimizations可以解决问题。

以下是在Ubuntu 16.04 LTS盒上对我有用的步骤-

  1. ssl文件中与Modules/Setup*相关的行被注释

  2. cd到您提取Python tar的目录

    cd /../../../Python-3.7.4/

  3. 在启用优化的情况下运行配置

    ./configure --enable-optimizations

  4. 运行make,然后进行安装

    make

    make install

答案 2 :(得分:1)

I encountered the problem when installing 3.8.11. I tried the above posts but they didn't work.

This is how I finally made it compile:

1) Install openssl 1.1.1g;
2) untar the tarball;
3) enter the source directory;
4) run ./config --prefix=/usr/local/openssl_1.1 --openssldir=/usr/local/openssl_1.1
to install to /usr/local/openssl_1.1.

make & make install.

You can customize the directory.
5)Download python 3.8 source tarball;
6)untar the tarball. Enter the source/Modules;
7) edit the file Setup;
8) find the lines:

SSL=/usr/local/ssl

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

change SSL=/usr/local/ssl to SSL=/usr/local/openssl_1.1

9) Switch to the source directory. run

./configure --prefix=/usr/local/python3.8 --with-openssl=/usr/local/openssl_1.1

10) export LD_LIBRARY_PATH=/usr/local/openssl_1.1/lib:$LD_LIBRARY_PATH

11) make & make install. If you need sudo, also export LD_LIBRARY_PATH in sudo

答案 3 :(得分:0)

我使用Anaconda发行版在Windows的Powershell上运行pip时遇到此问题。我在VSCode中运行它,但是我认为它没有太大的区别。

对我来说,快速的解决方法是使用Anaconda提示符安装所需的东西,效果很好。

答案 4 :(得分:0)

此命令对我来说效果很好。

cd Python-3.6.2
./configure --with-ssl
make
sudo make install

答案 5 :(得分:-1)

我遇到同样的问题在Windows 10。

我所做的是:

<强>步骤1:https://pypi.python.org/simple/requests,并下载最新版本(例如,请求-2.21.0.tar.gz)

<强>步骤2:解压下载的文件到一个文件夹(例如,C:\ TEMP \请求-2.21.0)。您可以将7zip用于此目的。

步骤3:点安装c:\ temp \ requests-2.21.0

注意:pip也可以安装本地文件夹。

对我有用。