Python - Sklearn - ImportError

时间:2017-07-12 08:55:02

标签: python python-2.7

我遇到导入sklearn的问题。

我已经通过pip安装了包,但是python无法导入库。我在Windows 10环境中使用python 2.7。

from sklearn.tree import DecisionTreeClassifier, export_graphviz

我得到的错误如下:

Traceback (most recent call last):
  File "classification.py", line 7, in <module>
    from sklearn.tree import DecisionTreeClassifier, export_graphviz
  File "C:\Python27\lib\site-packages\sklearn\__init__.py", line 56, in <module>
    from . import __check_build
ImportError: cannot import name __check_build

我读过有人通过安装SciPy(scipy-0.19.1.tar.gz)找到解决方案,但当我尝试通过pip安装时,提示符返回此消息:

C:\Python27\Scripts>pip install scipy
Collecting scipy
  Using cached scipy-0.19.1.tar.gz
Installing collected packages: scipy
  Running setup.py install for scipy ... error
    Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\filipp~1\\appdata\\local\\temp\\pip-build-mhb0vd\\scipy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\filipp~1\appdata\local\temp\pip-jsdbd3-record\install-record.txt --single-version-externally-managed --compile:

    Note: if you need reliable uninstall behavior, then install
    with pip instead of using `setup.py install`:

      - `pip install .`       (from a git repo or downloaded source
                               release)
      - `pip install scipy`   (last SciPy release on PyPI)


    lapack_opt_info:
    lapack_mkl_info:
      libraries mkl_rt not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\\libs']
      NOT AVAILABLE

    openblas_lapack_info:
      libraries openblas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\\libs']
      NOT AVAILABLE

    atlas_3_10_threads_info:
    Setting PTATLAS=ATLAS
    c:\python27\lib\site-packages\numpy\distutils\system_info.py:1051: UserWarning: Specified path C:\projects\numpy-wheels\windows-wheel-builder\atlas-builds\atlas-3.10.1-sse2-32\lib is invalid.
      pre_dirs = system_info.get_paths(self, section, key)
    <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
      NOT AVAILABLE

    atlas_3_10_info:
    <class 'numpy.distutils.system_info.atlas_3_10_info'>
      NOT AVAILABLE

    atlas_threads_info:
    Setting PTATLAS=ATLAS
    <class 'numpy.distutils.system_info.atlas_threads_info'>
      NOT AVAILABLE

    atlas_info:
    <class 'numpy.distutils.system_info.atlas_info'>
      NOT AVAILABLE

    c:\python27\lib\site-packages\numpy\distutils\system_info.py:572: 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.
      self.calc_info()
    lapack_info:
      libraries lapack not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\\libs']
      NOT AVAILABLE

    c:\python27\lib\site-packages\numpy\distutils\system_info.py:572: UserWarning:
        Lapack (http://www.netlib.org/lapack/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [lapack]) or by setting
        the LAPACK environment variable.
      self.calc_info()
    lapack_src_info:
      NOT AVAILABLE

    c:\python27\lib\site-packages\numpy\distutils\system_info.py:572: UserWarning:
        Lapack (http://www.netlib.org/lapack/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [lapack_src]) or by setting
        the LAPACK_SRC environment variable.
      self.calc_info()
      NOT AVAILABLE

    Running from scipy source directory.
    non-existing path in 'scipy\\integrate': 'quadpack.h'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\filipp~1\appdata\local\temp\pip-build-mhb0vd\scipy\setup.py", line 416, in <module>
        setup_package()
      File "c:\users\filipp~1\appdata\local\temp\pip-build-mhb0vd\scipy\setup.py", line 412, in setup_package
        setup(**metadata)
      File "c:\python27\lib\site-packages\numpy\distutils\core.py", line 135, in setup
        config = configuration()
      File "c:\users\filipp~1\appdata\local\temp\pip-build-mhb0vd\scipy\setup.py", line 336, in configuration
        config.add_subpackage('scipy')
      File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 1029, in add_subpackage
        caller_level = 2)
      File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 998, in get_subpackage
        caller_level = caller_level + 1)
      File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 935, in _get_configuration_from_setup_py
        config = setup_module.configuration(*args)
      File "scipy\setup.py", line 15, in configuration
        config.add_subpackage('linalg')
      File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 1029, in add_subpackage
        caller_level = 2)
      File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 998, in get_subpackage
        caller_level = caller_level + 1)
      File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 935, in _get_configuration_from_setup_py
        config = setup_module.configuration(*args)
      File "scipy\linalg\setup.py", line 20, in configuration
        raise NotFoundError('no lapack/blas resources found')
    numpy.distutils.system_info.NotFoundError: no lapack/blas resources found

    ----------------------------------------
Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\filipp~1\\appdata\\local\\temp\\pip-build-mhb0vd\\scipy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record c:\users\filipp~1\appdata\local\temp\pip-jsdbd3-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\filipp~1\appdata\local\temp\pip-build-mhb0vd\scipy\

感谢您的帮助,

菲利普。

2 个答案:

答案 0 :(得分:1)

here下载。然后使用cmd中的cd更改文件的路径。然后做pip install filename.whl。当然使用实际的文件名。

答案 1 :(得分:1)

打开终端(cmd)并在尝试导入sklearn之前尝试这些。

pip install -U scikit-learn

conda install scikit-learn

还要确保你有n and和scipy:

pip install numpy 
pip install scipy

尝试这个1:

安装scipy后重启python shell!

尝试2:

link安装numpy + mkl包,安装成功后重新启动python。

要安装whl文件,请使用:pip install some-package.whl

如果无效......

尝试这3:

为Python和PYTHONPATH环境变量设置系统路径变量

系统变量:将C:\ Python34添加到路径

用户变量:添加新:(名称)PYTHONPATH(值)C:\ Python34 \ Lib \ site-packages;

最后要尝试:

here

安装anaconda

然后运行:conda install scikit-learn