当我输入
import nltk
在Python解释器中,它给了我这个 -
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 105, in <module>
from collocations import *
File "/usr/local/lib/python2.7/dist-packages/nltk/collocations.py", line 38, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/__init__.py", line 16, in <module>
from nltk.metrics.scores import (accuracy, precision, recall, f_measure,
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/scores.py", line 16, in <module>
from scipy.stats.stats import betai
File "/usr/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 7, in <module>
from stats import *
File "/usr/lib/python2.7/dist-packages/scipy/stats/stats.py", line 198, in <module>
import distributions
File "/usr/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 87, in <module>
from new import instancemethod
File "new.py", line 3
^
IndentationError: expected an indented block
我看了一下我在/usr/lib/python2.7/中找到的new.py,发现一切正常。
"""Create new objects of various types.
Deprecated.This module is no longer required except for backward compatibility.
Objects of most types can now be created by calling the type object.
"""
from warnings import warnpy3k
warnpy3k("The 'new' module has been removed in Python 3.0; use the 'types' "
"module instead.", stacklevel=2)
del warnpy3k
from types import ClassType as classobj
from types import FunctionType as function
from types import InstanceType as instance
from types import MethodType as instancemethod
from types import ModuleType as module
from types import CodeType as code
任何解决方案?
答案 0 :(得分:3)
您有一个名为new.py
的本地文件。检查当前目录并重命名或删除它。
您可以在追溯中看到这一点:
File "/usr/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 87, in <module>
from new import instancemethod
File "new.py", line 3
前面的模块有一个完整的文件路径,但是new.py
文件没有,使它成为一个本地文件,它隐藏了scipy.stats.distributions
中的相对导入。