0

我想在 ubuntu12.04 上安装 scikit,我按照官方安装文档的说明在 bash 中键入以下命令:sudo apt-get install python-sklearn

接下来我输入测试指令nosetests sklearn --exe

但是我有很多导入错误!我搜索了谷歌,但发现很少有用的链接。我是python新手,我想通过scikit学习python和机器学习。所以请帮助我,谢谢。

以下是我在bash中运行nosetests命令时的错误信息。由于篇幅限制,我删除了一些错误。

  EEEEEE..............EE.....EE........EE.............EEE......EE..........
======================================================================
ERROR: Failure: ImportError (No module named joblib)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/cluster/__init__.py", line 10, in <module>
    from .hierarchical import ward_tree, Ward, WardAgglomeration
  File "/usr/lib/pymodules/python2.7/sklearn/cluster/hierarchical.py", line 20, in <module>
    from ..externals.joblib import Memory
  File "/usr/lib/pymodules/python2.7/sklearn/externals/joblib/__init__.py", line 3, in <module>
    from joblib import *
ImportError: No module named joblib

======================================================================
ERROR: Failure: ImportError (No module named joblib)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/covariance/__init__.py", line 14, in <module>
    from .graph_lasso_ import graph_lasso, GraphLasso, GraphLassoCV
  File "/usr/lib/pymodules/python2.7/sklearn/covariance/graph_lasso_.py", line 20, in <module>
    from ..linear_model import lars_path
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/__init__.py", line 16, in <module>
    from .least_angle import Lars, LassoLars, lars_path, LARS, LassoLARS, \
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/least_angle.py", line 19, in <module>
    from ..cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
  File "/usr/lib/pymodules/python2.7/sklearn/externals/joblib/__init__.py", line 3, in <module>
    from joblib import *
ImportError: No module named joblib

======================================================================
ERROR: Failure: ImportError (No module named joblib)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/__init__.py", line 18, in <module>
    from .lfw import load_lfw_pairs
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/lfw.py", line 34, in <module>
    from ..externals.joblib import Memory
  File "/usr/lib/pymodules/python2.7/sklearn/externals/joblib/__init__.py", line 3, in <module>
    from joblib import *
ImportError: No module named joblib


======================================================================
ERROR: Failure: ImportError (No module named joblib)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/externals/joblib/__init__.py", line 3, in <module>
    from joblib import *
ImportError: No module named joblib

======================================================================
ERROR: Failure: ImportError (cannot import name Parallel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/feature_extraction/tests/test_text.py", line 10, in <module>
    from sklearn.grid_search import GridSearchCV
  File "/usr/lib/pymodules/python2.7/sklearn/grid_search.py", line 18, in <module>
    from .cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: Failure: ImportError (cannot import name Parallel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/feature_selection/__init__.py", line 17, in <module>
    from .rfe import RFE
  File "/usr/lib/pymodules/python2.7/sklearn/feature_selection/rfe.py", line 13, in <module>
    from ..cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: Failure: ImportError (cannot import name Parallel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/__init__.py", line 16, in <module>
    from .least_angle import Lars, LassoLars, lars_path, LARS, LassoLARS, \
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/least_angle.py", line 19, in <module>
    from ..cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: Failure: ImportError (cannot import name Memory)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/metrics/cluster/tests/test_unsupervised.py", line 3, in <module>
    from .... import datasets
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/__init__.py", line 18, in <module>
    from .lfw import load_lfw_pairs
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/lfw.py", line 34, in <module>
    from ..externals.joblib import Memory
ImportError: cannot import name Memory

======================================================================
ERROR: Failure: ImportError (cannot import name Memory)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/metrics/tests/test_metrics.py", line 10, in <module>
    from ... import datasets
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/__init__.py", line 18, in <module>
    from .lfw import load_lfw_pairs
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/lfw.py", line 34, in <module>
    from ..externals.joblib import Memory
ImportError: cannot import name Memory

======================================================================
ERROR: Failure: ImportError (cannot import name Memory)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/utils/tests/test_sparsefuncs.py", line 5, in <module>
    from sklearn.datasets import make_classification
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/__init__.py", line 18, in <module>
    from .lfw import load_lfw_pairs
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/lfw.py", line 34, in <module>
    from ..externals.joblib import Memory
ImportError: cannot import name Memory

======================================================================
ERROR: Failure: ImportError (cannot import name Memory)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/utils/tests/test_svd.py", line 12, in <module>
    from sklearn.datasets.samples_generator import make_low_rank_matrix
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/__init__.py", line 18, in <module>
    from .lfw import load_lfw_pairs
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/lfw.py", line 34, in <module>
    from ..externals.joblib import Memory
ImportError: cannot import name Memory

======================================================================
ERROR: Tests that clone creates a correct deep copy.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_base.py", line 48, in test_clone
    from sklearn.feature_selection import SelectFpr, f_classif
  File "/usr/lib/pymodules/python2.7/sklearn/feature_selection/__init__.py", line 17, in <module>
    from .rfe import RFE
  File "/usr/lib/pymodules/python2.7/sklearn/feature_selection/rfe.py", line 13, in <module>
    from ..cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: Tests that clone doesn't copy everything.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_base.py", line 64, in test_clone_2
    from sklearn.feature_selection import SelectFpr, f_classif
  File "/usr/lib/pymodules/python2.7/sklearn/feature_selection/__init__.py", line 17, in <module>
    from .rfe import RFE
  File "/usr/lib/pymodules/python2.7/sklearn/feature_selection/rfe.py", line 13, in <module>
    from ..cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: sklearn.tests.test_base.test_is_classifier
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_base.py", line 109, in test_is_classifier
    from ..svm import SVC
  File "/usr/lib/pymodules/python2.7/sklearn/svm/__init__.py", line 13, in <module>
    from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC
  File "/usr/lib/pymodules/python2.7/sklearn/svm/classes.py", line 2, in <module>
    from ..linear_model.base import CoefSelectTransformerMixin
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/__init__.py", line 16, in <module>
    from .least_angle import Lars, LassoLars, lars_path, LARS, LassoLARS, \
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/least_angle.py", line 19, in <module>
    from ..cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: Failure: ImportError (cannot import name Memory)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_cross_validation.py", line 10, in <module>
    from ..datasets import make_regression
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/__init__.py", line 18, in <module>
    from .lfw import load_lfw_pairs
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/lfw.py", line 34, in <module>
    from ..externals.joblib import Memory
ImportError: cannot import name Memory

======================================================================
ERROR: Failure: ImportError (cannot import name Parallel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_grid_search.py", line 12, in <module>
    from sklearn.grid_search import GridSearchCV
  File "/usr/lib/pymodules/python2.7/sklearn/grid_search.py", line 18, in <module>
    from .cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: Failure: ImportError (cannot import name Memory)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_hmm.py", line 6, in <module>
    from sklearn.datasets.samples_generator import make_spd_matrix
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/__init__.py", line 18, in <module>
    from .lfw import load_lfw_pairs
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/lfw.py", line 34, in <module>
    from ..externals.joblib import Memory
ImportError: cannot import name Memory

======================================================================
ERROR: Failure: ImportError (cannot import name Parallel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_multiclass.py", line 13, in <module>
    from sklearn.svm import LinearSVC
  File "/usr/lib/pymodules/python2.7/sklearn/svm/__init__.py", line 13, in <module>
    from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC
  File "/usr/lib/pymodules/python2.7/sklearn/svm/classes.py", line 2, in <module>
    from ..linear_model.base import CoefSelectTransformerMixin
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/__init__.py", line 16, in <module>
    from .least_angle import Lars, LassoLars, lars_path, LARS, LassoLARS, \
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/least_angle.py", line 19, in <module>
    from ..cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: Failure: ImportError (cannot import name Parallel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_pipeline.py", line 9, in <module>
    from ..svm import SVC
  File "/usr/lib/pymodules/python2.7/sklearn/svm/__init__.py", line 13, in <module>
    from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC
  File "/usr/lib/pymodules/python2.7/sklearn/svm/classes.py", line 2, in <module>
    from ..linear_model.base import CoefSelectTransformerMixin
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/__init__.py", line 16, in <module>
    from .least_angle import Lars, LassoLars, lars_path, LARS, LassoLARS, \
  File "/usr/lib/pymodules/python2.7/sklearn/linear_model/least_angle.py", line 19, in <module>
    from ..cross_validation import check_cv
  File "/usr/lib/pymodules/python2.7/sklearn/cross_validation.py", line 21, in <module>
    from .externals.joblib import Parallel, delayed
ImportError: cannot import name Parallel

======================================================================
ERROR: Failure: ImportError (cannot import name Memory)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_pls.py", line 3, in <module>
    from sklearn.datasets import load_linnerud
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/__init__.py", line 18, in <module>
    from .lfw import load_lfw_pairs
  File "/usr/lib/pymodules/python2.7/sklearn/datasets/lfw.py", line 34, in <module>
    from ..externals.joblib import Memory
ImportError: cannot import name Memory

======================================================================
FAIL: Test either above import has failed for some reason
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/lib/pymodules/python2.7/sklearn/tests/test_init.py", line 22, in test_import_skl
    assert_equal(_top_import_error, None)
AssertionError: ImportError('cannot import name Parallel',) != None

----------------------------------------------------------------------
Ran 100 tests in 6.478s

FAILED (errors=26, failures=1)
4

1 回答 1

1

检查python-joblib包是否安装

sudo dpkg -l | grep joblib

如果没有返回,请尝试运行

apt-cache search joblib

应该有一个名为python-joblib: install it using

sudo apt-get install python-joblib

并重试。

编辑

您是对的,该软件包已安装,但 Python 似乎无法找到它(您的import joblib失败证明了这一点)。通常这意味着安装包的路径不是 Python 搜索路径的一部分。

您可以做的是从源手动安装模块并指定路径(似乎是/usr/lib/python2.7),或者使用诸如easy_install或之类的工具pip为您执行此操作。

正如您的指南中所述,pip install -U scikit-learn或者easy_install -U scikit-learn应该为您解决问题,因为您的库已经在那里......

于 2012-12-21T14:03:01.867 回答