简体   繁体   English

导入scikit-learn时出错

[英]Error with importing scikit-learn

I am trying to utilize the following code: 我试图利用以下代码:

from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
import numpy as np

I get this error: 我收到此错误:

ImportError: No module named sklearn.datasets

I then try to install scikit-learn , but get these errors: 然后,我尝试安装scikit-learn ,但出现以下错误:

pip install -U scikit-learn
  File "<ipython-input-9-6d283b29f0f9>", line 1
    pip install -U scikit-learn
              ^
SyntaxError: invalid syntax


easy_install -U scikit-learn
  File "<ipython-input-10-59440c1e5ef6>", line 1
    easy_install -U scikit-learn
                         ^
SyntaxError: invalid syntax

I am using Enthought Canopy Expresss which I thought "The Enthought Python Distribution already ships a recent version." 我使用的是Enthought Canopy Express,我认为“ Enthought Python发行版已经提供了最新版本。” as per http://scikit-learn.org/stable/install.html#enthought-python-distribution 按照http://scikit-learn.org/stable/install.html#enthought-python-distribution

How can I use scikit-learn ? 如何使用scikit-learn

Edit: 编辑:

After installing pip via easy_install pip I then tried running pip install -U scikit-learn and I get these errors (from my log file): 通过easy_install pip安装pip之后,我然后尝试运行pip install -U scikit-learn并从我的日志文件中得到以下错误:

running build_clib

No module named msvccompiler in numpy.distutils; trying from distutils

customize MSVCCompiler

Missing compiler_cxx fix for MSVCCompiler

customize MSVCCompiler using build_clib

building 'libsvm-skl' library

compiling C sources

Partial import of sklearn during the build process.

C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\system_info.py:564: UserWarning: Specified path C:\Users\vagrant\src\master-env\libs is invalid.

  warnings.warn('Specified path %s is invalid.' % d)

C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\system_info.py:564: UserWarning: Specified path C:\Users\vagrant\src\master-env\include is invalid.

  warnings.warn('Specified path %s is invalid.' % d)

C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\system_info.py:1494: UserWarning:

    Atlas (http://math-atlas.sourceforge.net/) libraries not found.

    Directories to search for the libraries can be specified in the

    numpy/distutils/site.cfg file (section [atlas]) or by setting

    the ATLAS environment variable.

  warnings.warn(AtlasNotFoundError.__doc__)

C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\system_info.py:1503: UserWarning:

    Blas (http://www.netlib.org/blas/) libraries not found.

    Directories to search for the libraries can be specified in the

    numpy/distutils/site.cfg file (section [blas]) or by setting

    the BLAS environment variable.

  warnings.warn(BlasNotFoundError.__doc__)

C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\distutils\system_info.py:1506: UserWarning:

    Blas (http://www.netlib.org/blas/) sources not found.

    Directories to search for the sources can be specified in the

    numpy/distutils/site.cfg file (section [blas_src]) or by setting

    the BLAS_SRC environment variable.

  warnings.warn(BlasSrcNotFoundError.__doc__)

sklearn\svm\setup.py:58: UserWarning:

    Blas (http://www.netlib.org/blas/) libraries not found.

    Directories to search for the libraries can be specified in the

    numpy/distutils/site.cfg file (section [blas]) or by setting

    the BLAS environment variable.

  warnings.warn(BlasNotFoundError.__doc__)

sklearn\setup.py:77: UserWarning:

    Blas (http://www.netlib.org/blas/) libraries not found.

    Directories to search for the libraries can be specified in the

    numpy/distutils/site.cfg file (section [blas]) or by setting

    the BLAS environment variable.

  warnings.warn(BlasNotFoundError.__doc__)

error: Unable to find vcvarsall.bat

----------------------------------------

Cleaning up...

  Removing temporary dir c:\users\cle1394\appdata\local\temp\pip_build_cle1394...
Command C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\Scripts\python.exe -c "import setuptools;__file__='c:\\users\\cle1394\\appdata\\local\\temp\\pip_build_cle1394\\scikit-learn\\setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\cle1394\appdata\local\temp\pip-1ysfly-record\install-record.txt --single-version-externally-managed failed with error code 1 in c:\users\cle1394\appdata\local\temp\pip_build_cle1394\scikit-learn

Exception information:
Traceback (most recent call last):
  File "C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\pip-1.4.1-py2.7.egg\pip\basecommand.py", line 134, in main
    status = self.run(options, args)
  File "C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\pip-1.4.1-py2.7.egg\pip\commands\install.py", line 241, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\pip-1.4.1-py2.7.egg\pip\req.py", line 1298, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\pip-1.4.1-py2.7.egg\pip\req.py", line 625, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\lib\site-packages\pip-1.4.1-py2.7.egg\pip\util.py", line 670, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command C:\Users\cle1394\AppData\Local\Enthought\Canopy\User\Scripts\python.exe -c "import setuptools;__file__='c:\\users\\cle1394\\appdata\\local\\temp\\pip_build_cle1394\\scikit-learn\\setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\cle1394\appdata\local\temp\pip-1ysfly-record\install-record.txt --single-version-externally-managed failed with error code 1 in c:\users\cle1394\appdata\local\temp\pip_build_cle1394\scikit-learn

I guess you are trying to put these commands into your Python command line. 我猜您正在尝试将这些命令放入Python命令行中。 They are supposed to work in your OS terminal. 它们应该在您的OS终端中工作。

  1. Scikit-learn is included in Canopy Basic (not Express) https://support.enthought.com/entries/22447950-scikit-learn https://www.enthought.com/products/canopy/package-index/ Scikit-learn包含在Canopy Basic(非Express)中https://support.enthought.com/entries/22447950-scikit-learn https://www.enthought.com/products/canopy/package-index/

  2. But you can install any package from the OS command line (as @sashkello points out, not python command line) as described here: https://support.enthought.com/entries/23389761-Installing-packages-into-Canopy-Python-from-the-command-line But depending on your OS and experience level, you may find this difficult because the package is not pure Python. 但是您可以按照以下说明从OS命令行安装任何软件包(如@sashkello指出的, 而不是 python命令行): https : //support.enthought.com/entries/23389761-Installing-packages-into-Canopy-Python从命令行开始,但是根据您的操作系统和经验水平,您可能会发现这很困难,因为该软件包不是纯Python。

对我来说,答案是为我的特定Python版本安装此http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM