我認爲當我輸入下面的句子時,我連續安裝了nltk軟件包 我得到錯誤。 是從安裝錯誤?或編碼?當使用python2.7下載語料庫NLTK時出現UnicodeDecodeError
#-*- coding: utf-8 -*-
import nltk
nltk.download()
Traceback (most recent call last):
File "C:/Lab/crawling/crawling_practice.py", line 2, in <module>
import nltk
File "C:\Anaconda2\lib\nltk\__init__.py", line 128, in <module>
from nltk.chunk import *
File "C:\Anaconda2\lib\nltk\chunk\__init__.py", line 155, in <module>
from nltk.data import load
File "C:\Anaconda2\lib\nltk\data.py", line 77, in <module>
if 'APPENGINE_RUNTIME' not in os.environ and os.path.expanduser('~/') != '~/':
File "C:\Anaconda2\lib\ntpath.py", line 311, in expanduser
return userhome + path[i:]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc1 in position 9: ordinal not in range(128)
您的計算機上的用戶名是什麼?它是否包含某種帶有口音/刻痕的拉丁字符? – alvas
實際上它在python2.7中失敗了。我將其更改爲版本3.5。它確實成功工作 – James