Python 安装几乎所有库的 pip 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16370583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:24:03  来源:igfitidea点击:

pip issue installing almost any library

pythonpipnltkeasy-install

提问by contentclown

I have a difficult time using pip to install almost anything. I'm new to coding, so I thought maybe this is something I've been doing wrong and have opted out to easy_install to get most of what I needed done, which has generally worked. However, now I'm trying to download the nltk library, and neither is getting the job done.

我很难使用 pip 安装几乎所有东西。我是编码新手,所以我想这可能是我做错了,并选择了 easy_install 来完成我需要完成的大部分工作,这通常有效。但是,现在我正在尝试下载 nltk 库,但都没有完成工作。

I tried entering

我试着进入

sudo pip install nltk

but got the following response:

但得到以下回应:

/Library/Frameworks/Python.framework/Versions/2.7/bin/pip run on Sat May  4 00:15:38 2013
Downloading/unpacking nltk

  Getting page https://pypi.python.org/simple/nltk/
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link]/simple/nltk/ when looking for download links for nltk

  Getting page [need more reputation to post link]/simple/
  Could not fetch URL https://pypi.python. org/simple/: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Cannot fetch index base URL [need more reputation to post link]

  URLs to search for versions for nltk:
  * [need more reputation to post link]
  Getting page [need more reputation to post link]
  Could not fetch URL [need more reputation to post link]: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm>

  Will skip URL [need more reputation to post link] when looking for download links for nltk

  Could not find any downloads that satisfy the requirement nltk

No distributions at all found for nltk

Exception information:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/basecommand.py", line 139, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/commands/install.py", line 266, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 1026, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/index.py", line 171, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for nltk

--easy_install installed fragments of the library and the code ran into trouble very quickly upon trying to run it.

Any thoughts on this issue? I'd really appreciate some feedback on how I can either get pip working or something to get around the issue in the meantime.

关于这个问题的任何想法?我真的很感激一些关于如何让 pip 工作或同时解决问题的反馈。

回答by Dougal

You're probably seeing this bug; see also here.

你可能会看到这个错误;另见此处

The easiest workaround is to downgrade pip to one that doesn't use SSL: easy_install pip==1.2.1. This loses you the security benefit of using SSL. The real solution is to use a Python distribution linked to a more recent SSL library.

最简单的解决方法是将 pip 降级为不使用 SSL 的easy_install pip==1.2.1. 这会使您失去使用 SSL 的安全优势。真正的解决方案是使用链接到更新的 SSL 库的 Python 发行版。

回答by akshayb

If it is only about nltk, I once faced similar problem. Try following guide for installation. Install NLTK

如果只是关于nltk,我曾经遇到过类似的问题。尝试按照安装指南进行操作。 安装 NLTK

If you are sure it doesn't work with any other module, you may have problem with different versions of Python installed.

如果您确定它不适用于任何其他模块,则您可能在安装了不同版本的 Python 时遇到了问题。

Or Give It a Try to see if it says pip is already installed.:

或者试试看它是否说 pip 已经安装。:

sudo apt-get install python-pip python-dev build-essential 

and see if it works.

看看它是否有效。

回答by pidge

Another cause of SSL errors can be a bad system time – certificates won't validate if it's too far off from the present.

SSL 错误的另一个原因可能是错误的系统时间 - 如果距离当前太远,证书将无法验证。

回答by Travis Oliphant

You can also use conda to install packages: See http://conda.pydata.org

您还可以使用 conda 安装软件包:请参阅http://conda.pydata.org

conda install nltk

conda install nltk

The best way to use conda is to download Miniconda, but you can also try

使用conda最好的方法是下载Miniconda,不过你也可以试试

pip install conda
conda init
conda install nltk

回答by spuder

I solved this issue with the following steps (on sles 11sp2)

我通过以下步骤解决了这个问题(在 sles 11sp2 上)

zypper remove pip
easy_install pip=1.2.1
pip install --upgrade scons

Here are the same steps in puppet (which should work on all distros)

以下是 puppet 中的相同步骤(应该适用于所有发行版)

  package { 'python-pip':
    ensure => absent,
  }
  exec { 'python-pip':
    command  => '/usr/bin/easy_install pip==1.2.1',
    require  => Package['python-pip'],
  }
  package { 'scons': 
    ensure   => latest,
    provider => pip,
    require  => Exec['python-pip'],
  }

回答by hobs

For me, the latest pip (1.5.6) works fine with the insecure nltk package if you just tell it not to be so picky about security:

对我来说,如果您只是告诉它不要对安全性如此挑剔,那么最新的 pip (1.5.6) 可以很好地与不安全的 nltk 软件包配合使用:

pip install --upgrade --force-reinstall --allow-all-external --allow-unverified ntlk nltk

回答by Ruben

I solved a similar problem by adding the --trusted-host pypi.python.orgoption

我通过添加--trusted-host pypi.python.org选项解决了类似的问题

回答by Oliver

I found it sufficient to specify the pypi host as trusted. Example:

我发现将 pypi 主机指定为可信主机就足够了。例子:

pip install --trusted-host pypi.python.org pytest-xdist
pip install --trusted-host pypi.python.org --upgrade pip

This solved the following error:

这解决了以下错误:

  Could not fetch URL https://pypi.python.org/simple/pytest-cov/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600) - skipping
  Could not find a version that satisfies the requirement pytest-cov (from versions: )
No matching distribution found for pytest-cov

Update April 2018: To anyone getting the TLSV1_ALERT_PROTOCOL_VERSION error: it has nothing to do with trusted-host/verification issue of the OP or this answer. Rather the TLSV1 error is because your interpreter does not support TLS v1.2, you must upgrade your interpreter. See for example https://news.ycombinator.com/item?id=13539034, http://pyfound.blogspot.ca/2017/01/time-to-upgrade-your-python-tls-v12.htmland https://bugs.python.org/issue17128.

2018 年 4 月更新:对于任何收到 TLSV1_ALERT_PROTOCOL_VERSION 错误的人:它与 OP 的可信主机/验证问题或此答案无关。而 TLSV1 错误是因为您的解释器不支持 TLS v1.2,您必须升级您的解释器。例如见https://news.ycombinator.com/item?id=13539034http://pyfound.blogspot.ca/2017/01/time-to-upgrade-your-python-tls-v12.htmlHTTPS ://bugs.python.org/issue17128

Update Feb 2019: For some it may be sufficient to upgrade pip. If the above error prevents you from doing this, use get-pip.py. E.g. on Linux,

2019 年 2 月更新:对于某些人来说,升级 pip 可能就足够了。如果上述错误阻止您执行此操作,请使用 get-pip.py。例如在 Linux 上,

curl https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

More details at https://pip.pypa.io/en/stable/installing/.

更多详细信息,访问https://pip.pypa.io/en/stable/installing/

回答by lostsoul29

If you're connecting through a proxy, execute export https_proxy=<your_proxy>(on Unix or Git Bash) and then retry installation.

如果您通过代理连接,请执行export https_proxy=<your_proxy>(在 Unix 或 Git Bash 上)然后重试安装。

If you're using Windows cmd, this changes to set https_proxy=<your_proxy>.

如果您使用的是 Windows cmd,这将更改为set https_proxy=<your_proxy>.

回答by user9175040

I did the following on Windows 7 to solve this problem.

我在 Windows 7 上做了以下操作来解决这个问题。

c:\Program Files\Python36\Scripts> pip install beautifulsoup4 --trusted-host *

c:\Program Files\Python36\Scripts> pip install beautifulsoup4 --trusted-host *

The --trusted-host seems to fix the SSL issue and * means every host.

--trusted-host 似乎解决了 SSL 问题,* 表示每个主机。

Of course this does not work because you get other errors since there is no version that satisfies the requirement beautifulsoup4, but I don't think that issue is related to the general question.

当然,这不起作用,因为您会收到其他错误,因为没有满足 beautifulsoup4 要求的版本,但我认为该问题与一般问题无关。