尝试为 Python 3 安装 scikit-learn 时出现“无法获取索引基 URL”错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38770169/
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-19 21:24:50  来源:igfitidea点击:

"Cannot fetch index base URL" error message when attempting to install scikit-learn for Python 3

pythonscikit-learnpython-3.4

提问by Roman

I try to install scikit-learn for Python 3. I do it in the following way:

我尝试为 Python 3 安装 scikit-learn。我按以下方式进行:

virtualenv model_env
source  model_env/bin/activate
pip3 install sklearn

As a result I get the following error message:

结果,我收到以下错误消息:

Downloading/unpacking sklearn
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement sklearn
Cleaning up...
No distributions at all found for sklearn

I had the same problem with pandaspackage and I have resolved it by using the following command:

我在pandas包上遇到了同样的问题,我已经使用以下命令解决了它:

sudo apt-get install python3-pandas

Unfortunately, the same approach does not work for the sklearn

不幸的是,同样的方法不适用于 sklearn

sudo apt-get install python3-sklearn

ADDED

添加

When I replace sklearnby scikit-learn, I have the same problem:

当我更换sklearnscikit-learn,我也有同样的问题:

Downloading/unpacking scikit-learn
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement scikit-learn
Cleaning up...
No distributions at all found for scikit-learn

ADDED 2

添加 2

As it has been recommended, I have try to use pip in combination with -vvv. Note that I use pip3instead of pip. This is what I get as the result:

正如推荐的那样,我尝试将 pip 与-vvv. 请注意,我使用pip3代替pip. 这是我得到的结果:

Downloading/unpacking scikit-learn
  Getting page https://pypi.python.org/simple/scikit-learn/
  Could not fetch URL https://pypi.python.org/simple/scikit-learn/: connection error: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/scikit-learn/ (Caused by <class 'OSError'>: [Errno 101] Network is unreachable)
  Will skip URL https://pypi.python.org/simple/scikit-learn/ when looking for download links for scikit-learn
  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 'OSError'>: [Errno 101] Network is unreachable)
  Will skip URL https://pypi.python.org/simple/ when looking for download links for scikit-learn
  Cannot fetch index base URL https://pypi.python.org/simple/
  URLs to search for versions for scikit-learn:
  * https://pypi.python.org/simple/scikit-learn/
  Getting page https://pypi.python.org/simple/scikit-learn/
  Could not fetch URL https://pypi.python.org/simple/scikit-learn/: connection error: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/scikit-learn/ (Caused by <class 'OSError'>: [Errno 101] Network is unreachable)
  Will skip URL https://pypi.python.org/simple/scikit-learn/ when looking for download links for scikit-learn
  Could not find any downloads that satisfy the requirement scikit-learn
Cleaning up...
  Removing temporary dir /tmp/pip_build_root...
No distributions at all found for scikit-learn
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python3/dist-packages/pip/req.py", line 1178, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/usr/lib/python3/dist-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 scikit-learn

Storing debug log for failure in /home/rngorb/.pip/pip.log

回答by Naveen Arun

Try using

尝试使用

pip3 install scikit-learn

回答by user8414391

First update your pip:

首先更新你的点子:

pip3 install --upgrade pip

Then install scikit-learn with arg "--user". Don't use sudo with pip as it will give problems:

然后使用参数“--user”安装 scikit-learn。不要将 sudo 与 pip 一起使用,因为它会产生问题:

pip install --user scikit-learn

回答by Ederson

I could solve it with this command:

我可以用这个命令解决它:

py -m pip install --user NAME_OF_THE_LIBRARY

It worked with- NumPy, SciPy, matplotlib, ipython, jupyter, pandas, sympy, nose and scikit-learn

它适用于 - NumPy、SciPy、matplotlib、ipython、jupyter、pandas、sympy、nose 和 scikit-learn

回答by David de la Iglesia

Maybe you should consider the use of Anacondawhich include both packages by default and make your life easy with tools to manage enviromentsand packages

也许您应该考虑使用Anaconda,它默认包含这两个包,并使用管理环境包的工具让您的生活变得轻松

回答by zemekeneng

If you want the convenience of Anaconda packages but the flexibility and minimalism of pippackage management, I suggest you try miniconda.

如果你想要 Anaconda 包的便利,但想要pip包管理的灵活性和极简主义,我建议你尝试miniconda

Once you install miniconda (remembering to source ~/.bash_profileor source ~/.bashrc), you can do this to setup your environment:

一旦你安装了 miniconda(记住source ~/.bash_profilesource ~/.bashrc),你可以这样做来设置你的环境:

conda create -n myenv scikit-learn pip python=3

This will get you a conda env with sklearn and pip in case you want to install libraries that are not supported as a conda package. The pip runs inside the conda env.

这将为您提供一个带有 sklearn 和 pip 的 conda env,以防您想安装不支持作为 conda 包的库。pip 在 conda 环境中运行。

回答by J.J. Hakala

Based on this answerfor question Python pip error: “Cannot fetch index base URL https://pypi.python.org/simple/”I would try to reinstall (and upgrade) pip with easy_install

基于问题Python pip error: “Cannot fetch index base URL https://pypi.python.org/simple/”的这个答案,我会尝试使用 easy_install 重新安装(和升级)pip

easy_install pip==8.1.2

I tried to reproduce your problem, and installing scikit-learn succeeded after pip install numpyand pip install scipyin a virtual environment created by pyenv-3.4.

我试图重现您的问题,并且在 pyenv-3.4 创建的虚拟环境中pip install numpy和之后安装 scikit-learn 成功pip install scipy

回答by Jishan Shaikh

It works perfectly fine. Try to install sklearn in the global environment i.e. in the terminal directly. For Ubuntu 17.04 (+ latest versions) try-

它工作得很好。尝试在全局环境中安装 sklearn,即直接在终端中。对于 Ubuntu 17.04(+ 最新版本),请尝试-

sudo apt-get install python3-sklearn

sudo apt-get install python3-sklearn

Similarly, for pandas

同样,对于熊猫

sudo apt-get install python3-pandas

sudo apt-get install python3-pandas

回答by Kadir Erturk

if you have multiple version of Python, make sure that you are at the correct site-package path before install.

如果您有多个版本的 Python,请确保您在安装前位于正确的站点包路径。

It was the case for me!!!

我就是这种情况!!!