使用 pip3 安装包时“Python 中的 ssl 模块不可用”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41328451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:49:04  来源:igfitidea点击:

"ssl module in Python is not available" when installing package with pip3

pythonsslpip

提问by Harukaze

I've install Python 3.4 and Python 3.6 on my local machine successfully, but am unable to install packages with pip3.

我已经在本地机器上成功安装了 Python 3.4 和 Python 3.6,但无法安装带有pip3.

When I execute pip3 install <package>, I get the following SSL relatederror:

当我执行时pip3 install <package>,我收到以下与 SSL 相关的错误:

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

How can I fix my Python3.x install so that I can install packages with pip install <package>?

如何修复我的 Python3.x 安装以便我可以安装包pip install <package>

回答by arsho

Step by step guide to install Python 3.6 and pip3 in Ubuntu

在 Ubuntu 中安装 Python 3.6 和 pip3 的分步指南

  1. Install the necessary packages for Python and ssl: $ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

  2. Download and unzip "Python-3.6.8.tar.xz" from https://www.python.org/ftp/python/into your home directory.

  3. Open terminal in that directory and run: $ ./configure

  4. Build and install: $ sudo make && sudo make install

  5. Install packages with: $ pip3 install package_name

  1. 为 Python 和 ssl 安装必要的包: $ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

  2. https://www.python.org/ftp/python/下载“Python-3.6.8.tar.xz”并将其解压缩到您的主目录中。

  3. 在该目录中打开终端并运行: $ ./configure

  4. 构建和安装: $ sudo make && sudo make install

  5. 安装软件包: $ pip3 install package_name

回答by The Aelfinn

If you are on Red Hat/CentOS:

如果您使用的是 Red Hat/CentOS:

# To allow for building python ssl libs
yum install openssl-devel
# Download the source of *any* python version
cd /usr/src
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
tar xf Python-3.6.2.tar.xz 
cd Python-3.6.2

# Configure the build w/ your installed libraries
./configure

# Install into /usr/local/bin/python3.6, don't overwrite global python bin
make altinstall

回答by juergi

If you are on Windows and use anacondathis worked for me:

如果您使用的是 Windows 并使用 anaconda,这对我有用

I tried a lot of other solutions which did not work (Environment PATH Variable changes ...)

我尝试了很多其他的解决方案,但都没有奏效(环境路径变量更改...)

The problem can be caused by DLLs in the Windows\System32 folder (e.g. libcrypto-1_1-x64.dll or libssl-1_1-x64.dll or others) placed there by other software.

该问题可能是由其他软件放置在 Windows\System32 文件夹(例如 libcrypto-1_1-x64.dll 或 libssl-1_1-x64.dll 或其他)中的 DLL 引起的。

The fix was installing openSSL from https://slproweb.com/products/Win32OpenSSL.htmlwhich replaces the dlls by more recent versions.

修复是从https://slproweb.com/products/Win32OpenSSL.html安装 openSSL,它用更新的版本替换了 dll。

回答by nathanyu

Agree with the answer by mastaBlasta. Worked for me. I encountered the same problem as the topic description.

同意mastaBlasta的回答。为我工作。我遇到了与主题描述相同的问题。

Environment: MacOS Sierra. And I use Homebrew.

环境:MacOS Sierra。我使用自制软件。

My solution:

我的解决方案:

  1. Reinstall openssl by brew uninstall openssl; brew install openssl
  2. According to the hints given by Homebrew, do the following:

    echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
    export LDFLAGS="-L/usr/local/opt/openssl/lib"
    export CPPFLAGS="-I/usr/local/opt/openssl/include"
    
  1. 重新安装openssl brew uninstall openssl; brew install openssl
  2. 根据 Homebrew 给出的提示,执行以下操作:

    echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
    export LDFLAGS="-L/usr/local/opt/openssl/lib"
    export CPPFLAGS="-I/usr/local/opt/openssl/include"
    

回答by dsomnus

I had a similar problem on OSX 10.11 due to installing memcached which installed python 3.7 on top of 3.6.

由于安装了在 3.6 之上安装了 python 3.7 的 memcached,我在 OSX 10.11 上遇到了类似的问题。

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

警告:pip 配置了需要 TLS/SSL 的位置,但是 Python 中的 ssl 模块不可用。

Spent hours on unlinking openssl, reinstalling, changing paths.. and nothing helped. Changing openssl version back from to older version did the trick:

花了几个小时断开openssl的链接,重新安装,更改路径......没有任何帮助。将 openssl 版本从旧版本更改回旧版本可以解决问题:

brew switch openssl 1.0.2e

I did not see this suggestion anywhere in internet. Hope it serves someone.

我在互联网上的任何地方都没有看到这个建议。希望它为某人服务。

回答by tingtinghuang

In Ubuntu, this can help:

在 Ubuntu 中,这可以帮助:

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

回答by Yanqi Huang

I encountered the same problem on windows 10. My very specific issue is due to my installation of Anaconda. I installed Anaconda and under the path Path/to/Anaconda3/, there comes the python.exe. Thus, I didn't install python at all because Anaconda includes python. When using pip to install packages, I found the same error report, pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available..

我在 Windows 10 上遇到了同样的问题。我非常具体的问题是由于我安装了 Anaconda。我安装了 Anaconda,在路径下Path/to/Anaconda3/,有python.exe. 因此,我根本没有安装 python,因为 Anaconda 包含 python。使用pip安装包时,发现同样的报错,pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available..

The solution was the following:

解决方案如下:

1) you can download python again on the official website;

1)可以在官重新下载python ;

2) Navigate to the directory where "Python 3.7 (64-bit).lnk"is located

2)导航到的目录,其中"Python 3.7 (64-bit).lnk"位于

3) import ssland exit()

3)import sslexit()

4) type in cmd, "Python 3.7 (64-bit).lnk" -m pip install tensorflowfor instance.

4)例如输入cmd "Python 3.7 (64-bit).lnk" -m pip install tensorflow

Here, you're all set.

在这里,你已经准备好了。

回答by Butterfly

If you are on Windows and use Anacondayou can try running "pip install ..." command in Anaconda Prompt instead of cmd.exe, as user willliu1995 suggests here. This was the fastest solution for me, that does not require installation of additional components.

如果您使用的是 Windows 并使用 Anaconda,您可以尝试在 Anaconda Prompt 中运行“pip install ...”命令而不是 cmd.exe,正如用户 willliu1995在此处建议的那样。这对我来说是最快的解决方案,不需要安装额外的组件。

回答by PengShaw

The problem probably caused by library missing.

问题可能是由于库丢失造成的。

Before you install python 3.6, make sure you install all the libraries required for python.

在安装 python 3.6 之前,请确保安装了 python 所需的所有库。

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

More information in How to Install Python 3.6.0 on Ubuntu & LinuxMint

如何在 Ubuntu 和 LinuxMint 上安装 Python 3.6.0 中的更多信息

回答by mastaBlasta

If you are on OSX and have compiled python from source:

如果您使用的是 OSX 并且已经从源代码编译了 python:

Install openssl using brew brew install openssl

使用 brew 安装 openssl brew install openssl

Make sure to follow the instructions brew gives you about setting your CPPFLAGSand LDFLAGS. In my case I am using the [email protected]brew formula and I need these 3 settings for the python build process to correctly link to my SSL library:

确保按照 brew 为您提供的有关设置CPPFLAGSLDFLAGS. 在我的情况下,我使用[email protected]brew 公式,我需要 python 构建过程的这 3 个设置才能正确链接到我的 SSL 库:

export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"

Assuming the library is installed at that location.

假设库安装在该位置。