我已经在我的本地机器上成功安装了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>?
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.
从源代码构建是我在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
我在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。