Python中的SSL模块不可用。

9

在继续学习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

请问有人知道我需要怎么做才能彻底解决这个问题吗?

非常感谢您的帮助。


3
可能是["SSL module in Python is not available" when installing package with pip3]的重复问题。 - rollstuhlfahrer
6个回答

10

我使用Linux发行版,并在安装Python 3.6后遇到了问题。我尝试了一些解决方案,最终解决了这个问题。我遵循的步骤如下。

对于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来安装所需的模块。


4
可行的解决方案,但有两处需要更正:
  1. cd /path/to/Python3.6/Module/ = .../Modules/
  2. ibncursesw5-dev 应该为 libncursesw5-dev。
- horbor
1
我也不应该在Setup文件中取消注释SSL=/usr/local/ssl这一行吗? - usernumber
我认为你的意思是使用 libncursesw5-dev 而不是 ibncursesw5-dev - Francis Rodrigues
1
这需要安装OpenSSL的开发包,Ubuntu上称为libssl-dev。请确保您也已经安装了它。 - e0k

4

通过使用--enable-optimizations选项运行./configure命令即可解决问题。

以下是在Ubuntu 16.04 LTS上为我工作的步骤-

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

  2. cd到您提取Python的目录

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

  3. 启用优化运行configure

    ./configure --enable-optimizations

  4. 运行make和make安装

    make

    make install


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

1
我在Windows上使用Anaconda发行版,在Powershell上运行pip时遇到了问题。我是在VSCode内运行的,但我认为这并没有什么区别。
对我来说,一个快速的解决方法是使用Anaconda提示符安装所需内容,这个方法可以正常工作。

0

这个命令对我非常有效。

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

3
配置警告:未识别选项:--with-ssl - Shawn

-1

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

我所做的是:

步骤1:前往https://pypi.python.org/simple/requests并下载最新版本(例如,requests-2.21.0.tar.gz)。

步骤2:将下载的文件解压缩到一个文件夹中(例如,c:\ temp \ requests-2.21.0)。您可以使用7zip进行此操作。

步骤3:pip install c:\ temp \ requests-2.21.0

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

这对我有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接