运行时出现NLTK Python错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运行时出现NLTK Python错误相关的知识,希望对你有一定的参考价值。
我已经在nltk
中安装了anaconda
并在本教程中尝试了一些示例pythonprogramming.net
在运行Classifier saving example 之后,它在anaconda
控制台上显示了一些错误,如下所示:
(C:UsersPublicAnaconda) C:UsersKalanka PC>pickle.py
Traceback (most recent call last):
File "C:UsersKalanka PCpickle.py", line 1, in <module>
import nltk
File "C:UsersPublicAnacondalibsite-packages
ltk\__init__.py", line 114, in <module>
from nltk.collocations import *
File "C:UsersPublicAnacondalibsite-packages
ltkcollocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "C:UsersPublicAnacondalibsite-packages
ltkmetrics\__init__.py", line 24, in <module>
from nltk.metrics.segmentation import windowdiff, ghd, pk
File "C:UsersPublicAnacondalibsite-packages
ltkmetricssegmentation.py", line 45, in <module>
import numpy as np
File "C:UsersPublicAnacondalibsite-packages
umpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:UsersPublicAnacondalibsite-packages
umpyadd_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:UsersPublicAnacondalibsite-packages
umpylib\__init__.py", line 8, in <module>
from .type_check import *
File "C:UsersPublicAnacondalibsite-packages
umpylib ype_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:UsersPublicAnacondalibsite-packages
umpycore\__init__.py", line 36, in <module>
from . import numeric
File "C:UsersPublicAnacondalibsite-packages
umpycore
umeric.py", line 37, in <module>
import pickle
File "C:UsersKalanka PCpickle.py", line 4, in <module>
from nltk.corpus import movie_reviews
File "C:UsersPublicAnacondalibsite-packages
ltkcorpus\__init__.py", line 66, in <module>
from nltk.corpus.reader import *
File "C:UsersPublicAnacondalibsite-packages
ltkcorpus
eader\__init__.py", line 59, in <module>
from nltk.corpus.reader.tagged import *
File "C:UsersPublicAnacondalibsite-packages
ltkcorpus
eader agged.py", line 18, in <module>
from nltk.tag import str2tuple, map_tag
File "C:UsersPublicAnacondalibsite-packages
ltk ag\__init__.py", line 63, in <module>
from nltk.tag.sequential import (SequentialBackoffTagger, ContextTagger,
File "C:UsersPublicAnacondalibsite-packages
ltk agsequential.py", line 26, in <module>
from nltk.classify import NaiveBayesClassifier
File "C:UsersPublicAnacondalibsite-packages
ltkclassify\__init__.py", line 93, in <module>
from nltk.classify.scikitlearn import SklearnClassifier
File "C:UsersPublicAnacondalibsite-packages
ltkclassifyscikitlearn.py", line 42, in <module>
from sklearn.feature_extraction import DictVectorizer
File "C:UsersPublicAnacondalibsite-packagessklearn\__init__.py", line 57, in <module>
from .base import clone
File "C:UsersPublicAnacondalibsite-packagessklearnase.py", line 10, in <module>
from scipy import sparse
File "C:UsersPublicAnacondalibsite-packagesscipy\__init__.py", line 70, in <module>
from numpy.random import rand, randn
File "C:UsersPublicAnacondalibsite-packages
umpy
andom\__init__.py", line 99, in <module>
from .mtrand import *
File "numpy.pxd", line 86, in init mtrand (numpy
andommtrandmtrand.c:42488)
AttributeError: module 'numpy' has no attribute 'dtype'
当我尝试再次安装时,它显示如下:
C:UsersKalanka PC>pip install nltk
Requirement already satisfied: nltk
in c:userspublicanacondalibsite-packages Requirement already satisfied: six in c:userspublicanacondalibsite-packages (from nltk)
答案
这里python文件的命名与pickle相同。因此在加载相关文件时会混淆。例如:文件名是pickle.py
,代码如下:
`import nltk`
`import random`
`import pickle`
另一答案
您可能已经保存了名为pickle.py的文件,因为它尝试导入pickle文件而不是模块中的标准pickle。
我在使用泡菜时遇到了类似的问题,我用名称pickle保存了代码文件。然后当我执行它时,查找你创建的文件而不是标准模块pickle
以上是关于运行时出现NLTK Python错误的主要内容,如果未能解决你的问题,请参考以下文章
安装 nltk 包时出现 ModuleNotFoundError: No module named '_sqlite3'
运行 python 3 代码时出现 python 2 语法错误
在片段java类中使用“this”和getLastSignedInAccount时出现错误[重复]
在 python2.7 中运行我的代码时出现错误如何修复该错误? [复制]