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


当前回答

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

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

or

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

\蟒蛇

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

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

\ bin \蟒蛇图书馆

\Anaconda\Scripts

\蟒蛇\图书馆

(anaconda \ condabin

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

其他回答

我在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。

我也遇到了同样的问题,并能够通过以下步骤解决:

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

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

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.

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

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

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

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