每当我尝试导入scipy
包时,我都会从nltk
收到异常。命令和错误如下所示:
>>> 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 114, in <module>
from nltk.collocations import *
File "/usr/local/lib/python2.7/dist-packages/nltk/collocations.py", line 39, 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/local/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 344, in <module>
from .stats import *
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py", line 176, in <module>
from . import distributions
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/_distn_infrastructure.py", line 43, in <module>
from new import instancemethod
File "new.py", line 107
return copy.deepcopy(self)
^
IndentationError: expected an indented block
我在终端(ubuntu 16.04 LTS系统)中执行了此命令。我没有发现任何有关此错误的信息,并且缩进看起来不错。
答案 0 :(得分:2)
SyntaxError位于您的文件new.py
中(我猜它在您当前的工作目录中)。尝试切换到没有new.py
文件的目录(或将new.py
文件移动到另一个目录中),然后内部scipy导入应该没有问题。
另一方面,你可以升级到scipy 0.19.x.他们删除了那里的导入,它应该没有问题。
请注意,命名builtin-modules之类的python文件总是一个坏主意!这是异常或意外行为的常见来源。