【问题标题】:"ssl module in Python is not available"“Python 中的 ssl 模块不可用”
【发布时间】:2021-08-09 14:27:02
【问题描述】:

我的教程还在继续学习 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

有人知道我需要做什么才能一劳永逸地解决这个问题吗?

在此先感谢

【问题讨论】:

标签: python pip


【解决方案1】:

自从新安装 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. cd /path/to/Python3.6/Module/ = .../Modules/ 2. ibncursesw5-dev = libncursesw5-dev
  • 我不应该也取消注释设置文件中的SSL=/usr/local/ssl 行吗?
  • 我认为您的意思是 libncursesw5-dev 而不是 ibncursesw5-dev
  • 这需要 OpenSSL development 包,它(在 Ubuntu 上)称为 libssl-dev。确保你也安装了这个。
【解决方案2】:

运行 ./configure--enable-optimizations 就可以了。

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

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

  2. cd 到你解压 Python tar 的目录

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

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

    ./configure --enable-optimizations

  4. 运行 make 然后进行安装

    make

    make install

【讨论】:

    【解决方案3】:

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

    对我来说,一个快速的转变是使用 Anaconda 提示符安装我需要的东西,它工作正常。

    【讨论】:

      【解决方案4】:
      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
      

      【讨论】:

        【解决方案5】:

        这个命令对我来说效果很好。

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

        【讨论】:

        • 配置:警告:无法识别的选项:--with-ssl
        【解决方案6】:

        我在 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 也可以安装本地文件夹。

        它对我有用。

        【讨论】:

          猜你喜欢
          • 2022-07-25
          • 1970-01-01
          • 2020-02-05
          • 1970-01-01
          • 2020-05-02
          • 1970-01-01
          • 2019-10-26
          • 1970-01-01
          • 2019-06-21
          相关资源
          最近更新 更多