2013-11-25 5 views
1

Я пытаюсь использовать следующий код:Ошибка при импорте 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 Enthought Python Distribution уже бедрами последней версии ». в соответствии с http://scikit-learn.org/stable/install.html#enthought-python-distribution

Как использовать scikit-learn?

Edit:

После установки pip через easy_install 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 

ответ

9

Я предполагаю, что вы пытаетесь поместить эти команды в вашу командную строку Python. Они должны работать на вашем терминале ОС.

+0

Я нахожусь на Windows. Вы хотите сказать, что мне нужно открыть командную строку и запустить эти команды? Не имеет значения, какой каталог? – user1477388

+1

Да, это то, что я имею в виду. Неважно, какой каталог. – sashkello

4
  1. Scikit-Learn входит в сени Basic (не Express) https://support.enthought.com/entries/22447950-scikit-learn https://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.

+0

Когда я ввожу 'sys.prefix' в командной строке, он читает' c: \\ users \\ dom \\ appdata \\ local \\ enthought \\ canopy \\ user', но когда я затем попробую 'easy_install pip', он говорит 'SyntaxError: недопустимый синтаксис' и указывает на последний' p' в 'easy_install pip'. Что я делаю не так? – user1477388

+1

@ user1477388: как сказал Сашкелло, а Джонатан выделен жирным шрифтом (!), Вы вводите команду в консоль Python. Вместо этого вы должны запустить это в оболочке. – DSM

+0

@DSM Я запустил эту команду в командной строке, то есть когда я иду запускать и набираю 'cmd'. – user1477388

Смежные вопросы