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


当前回答

从源代码构建是我在Ubuntu 22.10上的工作方式:

手动安装OpenSSL,在这里用OpenSSL 1.1.1测试,提取然后运行:

./config --prefix='/opt/openssl' --openssldir='/opt/ssl'
make
make install

然后使用旧版本的Python 3(这里是Python-3.8.16)运行:

export LD_RUN_PATH='/opt/openssl/lib'
export CC='gcc-12'  # sudo apt install gcc-12
./configure --enable-optimizations \
            --with-openssl='/opt/openssl' \
            --prefix='/opt/python/3.8' -C
make
make install

测试:

/opt/python/3.8/bin/python3 -c 'import ssl; print(ssl.OPENSSL_VERSION)'
OpenSSL 1.1.1s  1 Nov 2022

其他回答

如果你在Windows上使用anaconda,这对我来说是有效的:

我尝试了很多其他的解决方案,但没有工作(环境路径变量变化…)

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

修复方法是从https://slproweb.com/products/Win32OpenSSL.html安装openSSL,它将dll替换为最新版本。

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

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

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

降级openssl对我有用,

brew switch openssl 1.0.2s

特穆克斯

这是因为我没有安装现有的openssl版本。

pkg install openssl-tool

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.