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

其他回答

同意mastaBlasta的回答。为我工作。我遇到了与主题描述相同的问题。

环境:MacOS Sierra。我用的是自制啤酒。

我的解决方案:

重新安装openssl安装openssl 根据Homebrew提供的提示,执行以下操作: echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile . bat 出口LDFLAGS =“- l / usr /地方/ opt / openssl / lib” 出口CPPFLAGS = " - i / usr /地方/ opt / openssl /包括“

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

从源代码构建是我在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。

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

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

or

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

\蟒蛇

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

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

\ bin \蟒蛇图书馆

\Anaconda\Scripts

\蟒蛇\图书馆

(anaconda \ condabin

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