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

当我执行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>

如何修复我的Python3。pip install <package>?


当前回答

我在Debian9上安装python3.8.5时也遇到了同样的问题。我已经做了一个构建,但是当我尝试下载一些模块时,pip3.8出现了以下错误:

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

我已经搜索了问题的根源,发现python构建中有一个依赖于系统的部分是由系统独立的部分调用的。如果没有ssl,你只需要打开python终端,检查_ssl是否存在:

>>> help('modules')
.
.
_sre                enum                pwd                 wave
_ssl                errno               py_compile          weakref
_stat               faulthandler        pyclbr              webbrowser
.
.

如果不是,您的系统依赖ssl模块部分是缺失的。你也可以通过列出<python_installation_root>/lib/python3.8/lib-dynload的内容来检查:

>ls ./lib/python3.8/lib-dynload | grep ssl
_ssl.cpython-38-x86_64-linux-gnu.so

这个问题是由PengShaw编写的,因为在构建过程中缺少libssl-dev。因此,您必须遵循推荐的python安装流程。首先安装先决条件,然后构建和安装python。在没有devel版本的库的情况下安装导致我的案例中缺少系统依赖部分。在本例中是_ssl。

注意Debian和CentOS的devel库名称不同,因此请检查网上发布的安装提示是否适合您特定的Linux系统类型:

For Debian:
sudo apt install -y libbz2-dev libffi-dev libssl-dev
./configure --enable-optimizations
make
make altinstall


For CentOS:
sudo yum -y install bzip2-devel libffi-devel openssl-devel
./configure --enable-optimizations
make
make altinstall

在配置和evtl之前列出配置选项肯定是个好主意。使用一些额外的选项:

./configure --help

最后但并非最不重要的是,如果您使用——prefix作为非默认安装位置,请记住将<python_installation_root>/lib添加到LD_LIBRARY_PATH。

其他回答

你可以做这两件事中的任何一件:

在安装Anaconda时,选择将Anaconda添加到路径的选项。

or

从Anaconda的安装文件夹中找到这些(完整的)路径,并将它们添加到环境变量中:

\蟒蛇

\ \图书馆\ mingw-w64 \ bin的水蟒

\ \图书馆\ usr \ bin的水蟒

\ bin \蟒蛇图书馆

\Anaconda\Scripts

\蟒蛇\图书馆

(anaconda \ condabin

将上述路径添加到“Path”系统变量中,它应该不再显示错误了:)

I finally solve this issue. These are the detail of my env: Version of Python to install: 3.6.8 OS: Ubuntu 16.04.6 LTS Root access: No Some people suggest to install libssl-dev, but it did not work for me. I follow this link and I fixed it! In short, I download, extract, build, and install OpenSSL (openssl-1.1.1b.tar.gz). Then, I modify .bashrc file follow this link. Next, I download and extract Python-3.6.8.tgz. I edit Modules/Setup.dist to modify SSL path (lines around #211). I did ./configure --prefix=$HOME/opt/python-3.6.8, make and make install. Last, I modify my .bashrc. Notice that I do not include --enable-optimizations in ./configure.

前两天我也遇到了同样的问题,直到现在才解决。

我尝试使用digicert_high_asance_ev_root_ca的——trust-host选项。pem不工作,我无法安装ssl模块(它告诉它不能安装python版本大于2.6),设置$PIP_CERT变量也没有修复它,我安装了libssl1.0.2和libssl1.0.0。值得一提的是,我没有~/.pip/pip.conf文件,创建它也没有解决这个错误。

最终解决这个问题的方法是再次使用make安装python3.6。 下载Python-3.6.0。从网站TGZ,运行配置,然后使,使测试,使安装。希望这对你有用。

我在Debian9上安装python3.8.5时也遇到了同样的问题。我已经做了一个构建,但是当我尝试下载一些模块时,pip3.8出现了以下错误:

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

我已经搜索了问题的根源,发现python构建中有一个依赖于系统的部分是由系统独立的部分调用的。如果没有ssl,你只需要打开python终端,检查_ssl是否存在:

>>> help('modules')
.
.
_sre                enum                pwd                 wave
_ssl                errno               py_compile          weakref
_stat               faulthandler        pyclbr              webbrowser
.
.

如果不是,您的系统依赖ssl模块部分是缺失的。你也可以通过列出<python_installation_root>/lib/python3.8/lib-dynload的内容来检查:

>ls ./lib/python3.8/lib-dynload | grep ssl
_ssl.cpython-38-x86_64-linux-gnu.so

这个问题是由PengShaw编写的,因为在构建过程中缺少libssl-dev。因此,您必须遵循推荐的python安装流程。首先安装先决条件,然后构建和安装python。在没有devel版本的库的情况下安装导致我的案例中缺少系统依赖部分。在本例中是_ssl。

注意Debian和CentOS的devel库名称不同,因此请检查网上发布的安装提示是否适合您特定的Linux系统类型:

For Debian:
sudo apt install -y libbz2-dev libffi-dev libssl-dev
./configure --enable-optimizations
make
make altinstall


For CentOS:
sudo yum -y install bzip2-devel libffi-devel openssl-devel
./configure --enable-optimizations
make
make altinstall

在配置和evtl之前列出配置选项肯定是个好主意。使用一些额外的选项:

./configure --help

最后但并非最不重要的是,如果您使用——prefix作为非默认安装位置,请记住将<python_installation_root>/lib添加到LD_LIBRARY_PATH。

如果你在OSX上并从源代码编译python:

使用brew安装openssl

确保按照brew给出的关于设置CPPFLAGS和LDFLAGS的说明进行操作。在我的情况下,我使用openssl@1.1 brew公式,我需要这3个设置的python构建过程,以正确链接到我的SSL库:

export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

假设库安装在该位置。