我对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

当前回答

只是把这个放在这里,因为我没有看到其他人提到它。

你可以像这样设置全局可信主机为pip:

py -m pip config set global.trusted-host pypi.org

最重要的是,它将返回放置pip.ini/pip.conf的正确位置

其他回答

修复了我在OSX上的问题,在终端上运行以下程序:

open "/Applications/Python 3.9/Install Certificates.command"

这单子上的东西我都试过了!没有一个成功。 我意识到我的连接不稳定,所以我把调制解调器的电源插了一分钟 解决了我的问题:)

您可以通过以下方法解决CERTIFICATE_VERIFY_FAILED问题:

Use HTTP instead of HTTPS (e.g. --index-url=http://pypi.python.org/simple/). Use --cert <trusted.pem> or CA_BUNDLE variable to specify alternative CA bundle. E.g. you can go to failing URL from web-browser and import root certificate into your system. Run python -c "import ssl; print(ssl.get_default_verify_paths())" to check the current one (validate if exists). OpenSSL has a pair of environments (SSL_CERT_DIR, SSL_CERT_FILE) which can be used to specify different certificate databasePEP-476. Use --trusted-host <hostname> to mark the host as trusted. In Python use verify=False for requests.get (see: SSL Cert Verification). Use --proxy <proxy> to avoid certificate checks.

阅读更多:TLS/SSL包装套接字对象-验证证书。

永久固定pip配置

我有ssl问题,由于公司网络安全相关的netscope。我的机器是windows 10, python 3.9,下面的命令对我有用。

pip config set global.trusted-host \
    "pypi.org files.pythonhosted.org pypi.python.org" \
    --trusted-host=pypi.python.org \
    --trusted-host=pypi.org \
    --trusted-host=files.pythonhosted.org

在这里,pip永久信任这些站点,现在我们可以使用它们下载任何包。

如果已经编译了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