我对Python非常陌生,并试图在Windows 7上安装链接检查器。一些注意事项:
pip install is failing no matter the package. For example, > pip install scrapy also results in the SSL error.
Vanilla install of Python 3.4.1 included pip 1.5.6. The first thing I tried to do was install linkchecker. Python 2.7 was already installed, it came with ArcGIS. python and pip were not available from the command line until I installed 3.4.1.
> pip search linkchecker works. Perhaps that is because pip search does not verify the site's SSL certificate.
I am in a company network but we do not go through a proxy to reach the Internet.
Each company computer (including mine) has a Trusted Root Certificate Authority that is used for various reasons including enabling monitoring TLS traffic to https://google.com. Not sure if that has anything to do with it.
下面是运行pip install linkchecker后我的pip.log的内容:
Downloading/unpacking linkchecker
Getting page https://pypi.python.org/simple/linkchecker/
Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
Getting page https://pypi.python.org/simple/
Could not fetch URL https://pypi.python.org/simple/: connection error: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/ (Caused by <class 'http.client.CannotSendRequest'>: Request-sent)
Will skip URL https://pypi.python.org/simple/ when looking for download links for linkchecker
Cannot fetch index base URL https://pypi.python.org/simple/
URLs to search for versions for linkchecker:
* https://pypi.python.org/simple/linkchecker/
Getting page https://pypi.python.org/simple/linkchecker/
Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
Could not find any downloads that satisfy the requirement linkchecker
Cleaning up...
Removing temporary dir C:\Users\jcook\AppData\Local\Temp\pip_build_jcook...
No distributions at all found for linkchecker
Exception information:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Python34\lib\site-packages\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "C:\Python34\lib\site-packages\pip\req.py", line 1177, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "C:\Python34\lib\site-packages\pip\index.py", line 277, in find_requirement
raise DistributionNotFound('No distributions at all found for %s' % req)
pip.exceptions.DistributionNotFound: No distributions at all found for linkchecker
我发现最直接的方法是下载和使用“DigiCert高保证EV根CA”从DigiCert https://www.digicert.com/digicert-root-certificates.htm#roots
您可以访问https://pypi.python.org/,通过点击地址栏中的锁图标来验证证书颁发者,或者通过使用openssl来增加您的极客信用:
$ openssl s_client -connect pypi.python.org:443
CONNECTED(00000003)
depth=1 /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
0 s:/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=3359300/street=16 Allen Rd/postalCode=03894-4801/C=US/ST=NH/L=Wolfeboro,/O=Python Software Foundation/CN=www.python.org
i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
1 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA
证书链中的最后一个CN值为需要下载的CA的名称。
为了一次性的努力,请执行以下操作:
从DigiCert下载对照表
将CRT转换为PEM格式
2 .将PIP_CERT环境变量导出到PEM文件所在路径下
(最后一行假设您正在使用bash shell),然后运行pip。
curl -sO http://cacerts.digicert.com/DigiCertHighAssuranceEVRootCA.crt
openssl x509 -inform DES -in DigiCertHighAssuranceEVRootCA.crt -out DigiCertHighAssuranceEVRootCA.pem -text
export PIP_CERT=`pwd`/DigiCertHighAssuranceEVRootCA.pem
要使其可重用,请放入digicerthighassurance anceevrootca。然后在~/.bashrc中导出相应的PIP_CERT。
pip install gensim config --global http.sslVerify false
只需安装任何带有“config——global http. conf”的包。sslVerify false”语句
可以通过将pypi.org和files.pythonhosted.org以及旧的pypi.python.org设置为可信主机来忽略SSL错误。
$ pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <package_name>
注意:在2018年4月的某个时候,Python包索引从pypi.python.org迁移到pypi.org。这意味着使用旧域的“可信主机”命令不再有效,但您可以同时添加这两个命令。
永久解决
自从pip 10.0发布以来,你应该可以通过升级pip本身来永久地修复这个问题:
$ pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip setuptools
或者重新安装以获得最新版本:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
(…然后使用相关的Python解释器运行get-pip.py)。
PIP install <otherpackage>应该在此之后工作。如果没有,那么您将需要做更多的工作,如下所述。
您可能希望将受信任主机和代理添加到配置文件中。
pip.ini (Windows)或pip.conf (unix)
[global]
trusted-host = pypi.python.org
pypi.org
files.pythonhosted.org
替代解决方案(不太安全)
大多数答案都可能带来安全问题。
有两个变通方法可以帮助您轻松安装大多数python包:
使用easy_install:如果您真的很懒,不想浪费太多时间,请使用easy_install <package_name>。注意,有些包找不到,或者会出现小错误。
使用Wheel:下载python包的Wheel,使用pip命令pip install wheel_package_name。WHL安装包。
你有4个选择:
使用证书作为参数
$ pip install --cert /path/to/mycertificate.crt linkchecker
使用pip.conf中的证书
创建这个文件:
$HOME/.pip/pip.conf (Linux)
%HOME%\pip\pip.ini (Windows)
然后加上这几行:
[global]
cert = /path/to/mycertificate.crt
忽略证书并使用HTTP
$ pip install --trusted-host pypi.python.org linkchecker
忽略证书,在pip.conf中使用HTTP
创建这个文件:
$HOME/.pip/pip.conf (Linux)
%HOME%\pip\pip.ini (Windows)
然后加上这几行:
[global]
trusted-host = pypi.python.org
源
https://pip.pypa.io/en/latest/user_guide/#configuration
TLDR:
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt -vvv
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <packageName> -vvv
所以,我已经有了30多个问题的答案,但在2020年6月(封锁期间),什么都对我没用。
这些都是在过去的不同时刻被给予的。我将努力让这个答案在未来的任何时候都适用。
问题是,当pip安装包时,它会尝试连接存储包的主机URL,并且在下载时不相信URL。
有两种方法可以解决这个问题:
容易的,不安全的:
1. 检查哪个URL被pip击中下载包。
pip install <packageName> -vvv
如果你仔细检查输出,你会发现它可能会指向一些URL,比如pypi.org或者pypi.python.org。
如果是,只需添加可信主机选项到命令如下:
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <packageName> -vvv
或者如果你使用的是需求文件:
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt -vvv
安全的方法:
转到这些URL并下载它们的公共证书(只要谷歌如何下载),创建一个链,将其存储为.pem文件,并运行以下命令:
pip --cert YourPemFile.pem install <packageName>
尽管有40个答案,但我认为没有一个完全解决了我的问题。
我在macOS Catalina 10.15.5上,在公司代理的后面。
在尝试安装或升级包时,提示以下错误
>>> pip install <package name>
Looking in indexes: https://pypi.org/simple, https://data:****@pypi.<company>.com/simple/
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)'))': <package name>
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)'))': <package name>
@Steve_Tauber的回答pip——cert /etc/ssl/certs/FOO_Root_CA。Pem安装链接检查器让我的方式有一部分。
我能够使用现有的cert文件成功安装包,如下所示:
pip install --cert /Users/me/opt/anaconda3/ssl/cert.pem --upgrade pip
但是我不想每次使用pip时都使用cert标志…
答案是更新环境变量:
CERT_PATH=/Users/me/opt/anaconda3/ssl/cert.pem
export SSL_CERT_FILE=${CERT_PATH}
export REQUESTS_CA_BUNDLE=${CERT_PATH}
现在我可以安装了。
如果已经编译了Python,则执行以下操作在Python中启用SSL。
wget --no-check-certificate https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz
tar -zxf Python-3.9.10.tgz
cd Python-3.9.10
mkdir /home/$USER/tools
export INSTALL_BASE_PATH=/home/$USER/tools
mkdir -p {INSTALL_BASE_PATH}/ssl
vi ./Modules/Setup # Modify below lines in this file to these
SSL = {INSTALL_BASE_PATH} / SSL
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto .使用实例
./configure \
--prefix=${INSTALL_BASE_PATH} \
--enable-shared \
--enable-ipv6 \
LDFLAGS=-Wl,-rpath=${INSTALL_BASE_PATH}/lib,--disable-new-dtags
make
make install