Python(nltk)-UnicodeDecodeError:&x27;ascii';编解码器可以';t解码字节

Python(nltk)-UnicodeDecodeError:&x27;ascii';编解码器可以';t解码字节,python,error-handling,compiler-errors,nltk,Python,Error Handling,Compiler Errors,Nltk,我是NLTK的新手。我得到了这个错误,我搜索了编码/解码,特别是UnicodeDecodeError,但是这个错误似乎是NLTK源代码特有的 以下是错误: Traceback (most recent call last): File "A:\Python\Projects\Test\main.py", line 2, in <module> print(pos_tag(word_tokenize("John's big idea isn't all that bad."

我是NLTK的新手。我得到了这个错误,我搜索了编码/解码,特别是UnicodeDecodeError,但是这个错误似乎是NLTK源代码特有的

以下是错误:

Traceback (most recent call last):
  File "A:\Python\Projects\Test\main.py", line 2, in <module>
    print(pos_tag(word_tokenize("John's big idea isn't all that bad.")))
  File "A:\Python\Python\lib\site-packages\nltk\tag\__init__.py", line 100, in pos_tag
    tagger = load(_POS_TAGGER)
  File "A:\Python\Python\lib\site-packages\nltk\data.py", line 779, in load
    resource_val = pickle.load(opened_resource)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcb in position 0: ordinal not in range(128)
from nltk import pos_tag, word_tokenize
print(pos_tag(word_tokenize("John's big idea isn't all that bad.")))
重复:

长话短说:NLTK与Python 3不兼容。你必须使用NLTK 3,这听起来有点实验性

尝试使用模块“textclean”

Python代码

from textclean.textclean import textclean
text = textclean.clean("John's big idea isn't all that bad.")
print pos_tag(word_tokenize(text))

我和你有同样的问题。我在Windows7中使用Python3.4

我已经安装了“nltk-3.0.0.win32.exe”(从)。但当我安装“nltk-3.0a4.win32.exe”(从)时,我的nltk.pos_标记问题就解决了。检查一下


编辑:如果第二个链接不起作用,您可以查看。

试试这个。。。NLTK 3.0.1和Python 2.7.x

import io
f = io.open(txtFile, 'rU', encoding='utf-8')

是pos_标记函数导致了错误。这里显示的代码中没有任何东西会产生错误。打印要传递的字符串的
repr
。返回字符串,但字符串周围有
。@MarkRansom我不知道你的意思,函数
pos\u标记
导致了错误。我认为编码错误是在pickle.load函数上生成的。我不知道该怎么办。我正在使用NLTK 3和Python 3.4,但仍然会出现这个错误。这个模块听起来像是个可怕的想法。这里尤其糟糕,因为错误发生在试图解码pickle时——如果你试图盲目地“清理”它,你将无法修复地破坏这种结构化数据格式。第二个链接似乎被破坏了。你有其他的链接吗?很有魅力!我使用nltk 3.1和Python 2.7.x。这太棒了!你能解释一下为什么使用io可以解决这个问题吗?
import io
f = io.open(txtFile, 'rU', encoding='utf-8')