我已经在我的本地机器上成功安装了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。
ssl模块是用于访问操作系统(OS)套接字(Lib/ssl.py)的TLS/ ssl包装器。因此,当ssl模块不可用时,可能是您没有安装OS OpenSSL库,或者在安装Python时没有找到这些库。让我们假设这是后面的情况(也就是说:你已经安装了OpenSSL,但在安装Python时没有正确链接它们)。
我还假定您是从源代码安装的。如果你是从二进制文件(例如:windows .exe文件),或包(Mac .dmg,或Ubuntu apt)安装,在安装过程中你可以做的不多。
在配置python安装的步骤中,您需要指定将使用OS OpenSSL进行链接的位置:
# python 3.8 beta
./configure --with-openssl="your_OpenSSL root"
那么,在哪里可以找到已安装的OpenSSL目录呢?
# ubuntu
locate ssl.h | grep '/openssl/ssl.h'
/home/user/.linuxbrew/Cellar/openssl/1.0.2r/include/openssl/ssl.h
/home/user/envs/py37/include/openssl/ssl.h
/home/user/miniconda3/envs/py38b3/include/openssl/ssl.h
/home/user/miniconda3/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.0.2s-h7b6447c_0/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1b-h7b6447c_1/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1c-h7b6447c_1/include/openssl/ssl.h
/usr/include/openssl/ssl.h
您的系统可能与我的不同,但正如您在这里看到的,我安装了许多不同的openssl库。在撰写本文时,python 3.8期望openssl 1.0.2或1.1:
Python要求使用X509_VERIFY_PARAM_set1_host()与OpenSSL 1.0.2或1.1兼容的libssl。
因此,您需要验证哪些已安装的库可以用于链接
/usr/bin/openssl version
OpenSSL 1.0.2g 1 Mar 2016
./configure --with-openssl="/usr"
make && make install
您可能需要尝试一些库,或者安装一个新的库,以找到适合您的Python和操作系统的库。
我也遇到了同样的问题,并能够通过以下步骤解决:
sudo yum install -y libffi-devel
sudo yum install openssl-devel
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
sudo tar xf Python-3.7.1.tar.xz
cd Python-3.7.1
sudo ./configure --enable-optimizations
# Install into /usr/local/bin/python3.7, don't overwrite global python bin
sudo make altinstall
根据烫发的不同,你可能不需要sudo。
Results:
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1
现在应该可以运行了吗
python3.7 -V
and
pip3.7 -V
安装包时:
pip3.7 install pandas
或者根据烫发,你也可以像这样添加——user标志:
pip3.7 install pandas --user