无法导入sklearn。第一次导入sklearn时,显示以下内容:-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/sklearn/__init__.py", line 134, in <module>
from .base import clone
File "/usr/local/lib/python2.7/dist-packages/sklearn/base.py", line 13, in <module>
from .utils.fixes import signature
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/__init__.py", line 10, in <module>
from .validation import (as_float_array,
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 23, in <module>
from ..externals.joblib import Memory
File "/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/__init__.py", line 127, in <module>
from .parallel import Parallel
File "/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/parallel.py", line 27, in <module>
from .format_stack import format_outer_frames
File "/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/format_stack.py", line 35, in <module>
generate_tokens = tokenize.tokenize
AttributeError: 'module' object has no attribute 'tokenize'
然后,我重新导入它(在第一次尝试后立即),它向我显示了这个:-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/sklearn/__init__.py", line 133, in <module>
from . import __check_build
ImportError: cannot import name __check_build
我通过执行以下提到的步骤来重新安装sklearn,但问题仍然相同。
步骤:-
pip uninstall sklearn
pip uninstall scikit-learn
pip install sklearn
另一方面,我不知道它与该nltk库有什么关系,因为当我尝试import nltk
时,它会产生相同的错误。 nltk导入时的错误如下所示。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import *
File "/usr/lib/python2.7/dist-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/usr/lib/python2.7/dist-packages/nltk/chunk/api.py", line 13, in <module>
from nltk.parse import ParserI
File "/usr/lib/python2.7/dist-packages/nltk/parse/__init__.py", line 79, in <module>
from nltk.parse.transitionparser import TransitionParser
File "/usr/lib/python2.7/dist-packages/nltk/parse/transitionparser.py", line 21, in <module>
from sklearn.datasets import load_svmlight_file
File "/usr/local/lib/python2.7/dist-packages/sklearn/__init__.py", line 134, in <module>
from .base import clone
File "/usr/local/lib/python2.7/dist-packages/sklearn/base.py", line 13, in <module>
from .utils.fixes import signature
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/__init__.py", line 10, in <module>
from .validation import (as_float_array,
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 23, in <module>
from ..externals.joblib import Memory
File "/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/__init__.py", line 127, in <module>
from .parallel import Parallel
File "/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/parallel.py", line 27, in <module>
from .format_stack import format_outer_frames
File "/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/format_stack.py", line 35, in <module>
generate_tokens = tokenize.tokenize
AttributeError: 'module' object has no attribute 'tokenize'
如果我在第一次导入后立即重新导入nltk,就像sklearn所做的那样,它将向我显示:-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import *
File "/usr/lib/python2.7/dist-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/usr/lib/python2.7/dist-packages/nltk/chunk/api.py", line 15, in <module>
from nltk.chunk.util import ChunkScore
File "/usr/lib/python2.7/dist-packages/nltk/chunk/util.py", line 13, in <module>
from nltk.tag.mapping import map_tag
File "/usr/lib/python2.7/dist-packages/nltk/tag/__init__.py", line 63, in <module>
from nltk.tag.sequential import (SequentialBackoffTagger, ContextTagger,
File "/usr/lib/python2.7/dist-packages/nltk/tag/sequential.py", line 25, in <module>
from nltk.classify import NaiveBayesClassifier
File "/usr/lib/python2.7/dist-packages/nltk/classify/__init__.py", line 86, in <module>
from nltk.classify.megam import config_megam, call_megam
File "/usr/lib/python2.7/dist-packages/nltk/classify/megam.py", line 29, in <module>
from nltk import compat
ImportError: cannot import name compat
版本:-
Platform: Linux-4.15.0-29-generic-x86_64-with-Ubuntu-16.04-xenial
Sys: 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609]
Scipy: 0.17.0
Numpy: 1.14.5
任何帮助将不胜感激。