导入scikit学习时出错



我正在尝试使用以下代码:

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

我得到这个错误:

ImportError: No module named sklearn.datasets

然后我尝试安装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

我正在使用Enthought Canopy Expresss,我认为"The Enthoughter Python Distribution已经发布了最新版本。"http://scikit-learn.org/stable/install.html#enthought-python分发

如何使用scikit-learn

编辑:

在通过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:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagesnumpydistutilssystem_info.py:564: UserWarning: Specified path C:Usersvagrantsrcmaster-envlibs is invalid.
  warnings.warn('Specified path %s is invalid.' % d)
C:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagesnumpydistutilssystem_info.py:564: UserWarning: Specified path C:Usersvagrantsrcmaster-envinclude is invalid.
  warnings.warn('Specified path %s is invalid.' % d)
C:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagesnumpydistutilssystem_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:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagesnumpydistutilssystem_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:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagesnumpydistutilssystem_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__)
sklearnsvmsetup.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__)
sklearnsetup.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:userscle1394appdatalocaltemppip_build_cle1394...
Command C:Userscle1394AppDataLocalEnthoughtCanopyUserScriptspython.exe -c "import setuptools;__file__='c:\users\cle1394\appdata\local\temp\pip_build_cle1394\scikit-learn\setup.py';exec(compile(open(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record c:userscle1394appdatalocaltemppip-1ysfly-recordinstall-record.txt --single-version-externally-managed failed with error code 1 in c:userscle1394appdatalocaltemppip_build_cle1394scikit-learn
Exception information:
Traceback (most recent call last):
  File "C:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagespip-1.4.1-py2.7.eggpipbasecommand.py", line 134, in main
    status = self.run(options, args)
  File "C:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagespip-1.4.1-py2.7.eggpipcommandsinstall.py", line 241, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "C:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagespip-1.4.1-py2.7.eggpipreq.py", line 1298, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "C:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagespip-1.4.1-py2.7.eggpipreq.py", line 625, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "C:Userscle1394AppDataLocalEnthoughtCanopyUserlibsite-packagespip-1.4.1-py2.7.eggpiputil.py", line 670, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command C:Userscle1394AppDataLocalEnthoughtCanopyUserScriptspython.exe -c "import setuptools;__file__='c:\users\cle1394\appdata\local\temp\pip_build_cle1394\scikit-learn\setup.py';exec(compile(open(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record c:userscle1394appdatalocaltemppip-1ysfly-recordinstall-record.txt --single-version-externally-managed failed with error code 1 in c:userscle1394appdatalocaltemppip_build_cle1394scikit-learn

我猜您正试图将这些命令放入Python命令行中。它们应该在您的操作系统终端中工作。

  1. Scikit学习包含在Canopy Basic(非Express)中https://support.enthought.com/entries/22447950-scikit-learnhttps://www.enthought.com/products/canopy/package-index/

  2. 但是,您可以从OS命令行安装任何程序包(正如@sashkello所指出的,而不是python命令行),如下所述:https://support.enthought.com/entries/23389761-Installing-packages-into-Canopy-Python-from-the-command-line但根据您的操作系统和经验水平,您可能会发现这很困难,因为该包不是纯Python。

我的答案是安装http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit学习我的Python特定版本。

相关内容

  • 没有找到相关文章

最新更新