我已经在我的本地机器上成功安装了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>?


当前回答

如果你在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"

假设库安装在该位置。

其他回答

如果你在Windows上使用Anaconda,你可以尝试在Anaconda提示符中运行“pip install…”命令,而不是cmd.exe,就像用户willliu1995在这里建议的那样。这对我来说是最快的解决方案,不需要安装额外的组件。

如果在窗户和使用蟒蛇,比我先解决它,

conda activate
pip install <lib>

这对我很管用。

在使用pyenv来管理Mac OS Catalina上的python安装的情况下,我必须先用brew安装openssl,然后运行pyenv install 3.7.8,这似乎是使用homebrew中的openssl来构建python安装(它甚至在安装输出中这样说)。然后pyenv global 3.7.8,我离开了。

在macos上,使用下面的命令配置python 3.8.1将解决这个问题,我认为它也适用于Linux。

./configure --enable-optimizations --with-openssl=/usr/local/opt/openssl@1.1/

根据您的系统更改dir参数。

如果你使用的是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