Python(nltk)-UnicodeDecodeError:'ascii'编解码器无法解码字节 [英] Python (nltk) - UnicodeDecodeError: 'ascii' codec can't decode byte

查看:36
本文介绍了Python(nltk)-UnicodeDecodeError:'ascii'编解码器无法解码字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 NLTK 的新手.我收到了这个错误,我四处寻找编码/解码,特别是 UnicodeDecodeError 但这个错误似乎特定于 NLTK 源代码.

I'm new to NLTK. I'm getting this error and I've searched around for encoding/decoding and specifically the UnicodeDecodeError but this error seems specific to the NLTK source code.

错误如下:

Traceback (most recent call last):
  File "A:PythonProjectsTestmain.py", line 2, in <module>
    print(pos_tag(word_tokenize("John's big idea isn't all that bad.")))
  File "A:PythonPythonlibsite-packages
ltk	ag\__init__.py", line 100, in pos_tag
    tagger = load(_POS_TAGGER)
  File "A:PythonPythonlibsite-packages
ltkdata.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)

我该如何解决这个错误?

以下是导致错误的原因:

How do I go around fixing this error?

Here's what causes the error:

from nltk import pos_tag, word_tokenize
print(pos_tag(word_tokenize("John's big idea isn't all that bad.")))

推荐答案

试试这个... NLTK 3.0.1 with Python 2.7.x

try this... NLTK 3.0.1 with Python 2.7.x

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

这篇关于Python(nltk)-UnicodeDecodeError:'ascii'编解码器无法解码字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆