ImportError:无法导入名称重写

时间:2018-03-21 05:34:20

标签: python nltk

所以我尝试使用nltk并将所有内容安装到正确的环境中。 当我单独运行import命令时,一切正常,但是当我在Python中运行所有代码时,我收到此错误ImportError。 有谁知道如何解决这个问题?请帮忙,谢谢!

import nltk
import random
from nltk.classify.scikitlearn import SklearnClassifier
import pickle
from sklearn.naive_bayes import MultinomialNB, BernoulliNB
from sklearn.linear_model import LogisticRegression, SGDClassifier
from sklearn.svm import SVC, LinearSVC, NuSVC
from nltk.classify import ClassifierI
from statistics import mode
from nltk.tokenize import word_tokenize   
 Traceback (most recent call last):
  File "code/pickle.py", line 1, in <module>
    import nltk
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2./site-packages/nltk/__init__.py", line 89, in <module>
    from nltk.internals import config_java
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/internals.py", line 11, in <module>
    import subprocess
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 75, in <module>
    import pickle
  File "/Users/jpike/Desktop/Code/pickle.py", line 3, in <module>
    from nltk.classify.scikitlearn import SklearnClassifier
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/classify/__init__.py", line 85, in <module>
    from nltk.classify.api import ClassifierI, MultiClassifierI
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/classify/api.py", line 21, in <module>
    from nltk.internals import overridden
ImportError: cannot import name overridden

1 个答案:

答案 0 :(得分:0)

我所做的工作将文件/usr/lib/python3.5/pickle.py重命名为/usr/lib/python3.5/pickle2.py,问题得以解决。不知道此错误与导入错误有何关系。我只是按照DYZ给出的上述说明