系统:Windows 7 64位
软件: python-2.7.10.msi,nltk-3.0.4.win32.exe
问题描述:
我今天使用我的桌面安装Python 2.7.10( 32位版本),然后安装nltk 3.0.4。正确设置了Python的路径:
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sys
>>> sys.path
['', 'C:\\Python27\\Lib\\idlelib', 'C:\\Python27\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages']
>>>
然后我在Shell中尝试import nltk
,然后我明白了:
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import nltk
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk
File "C:\Python27\lib\site-packages\nltk\__init__.py", line 128, in <module>
from nltk.align import *
File "C:\Python27\lib\site-packages\nltk\align\__init__.py", line 18, in <module>
from nltk.align.bleu_score import bleu
File "C:\Python27\lib\site-packages\nltk\align\bleu_score.py", line 15, in <module>
from nltk.tokenize import word_tokenize
File "C:\Python27\lib\site-packages\nltk\tokenize\__init__.py", line 62, in <module>
from nltk.data import load
File "C:\Python27\lib\site-packages\nltk\data.py", line 76, in <module>
if 'APPENGINE_RUNTIME' not in os.environ and os.path.expanduser('~/') != '~/':
File "C:\Python27\lib\ntpath.py", line 311, in expanduser
return userhome + path[i:]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 9: ordinal not in range(128)
>>>
我尝试了几种方法:1)使用不同的版本,例如Python 2.6和nltk 3.0.0,但没有解决。 2)从官方网站使用补丁,不能正常工作。
HOWEVER ,当我使用我的笔记本电脑(Win7 64位),使用相同版本的Python和nltk时,一切正常!我不知道原因。所以有人能告诉我它为什么会发生吗?
答案 0 :(得分:0)
我通过更改非Unicode程序的操作系统区域设置解决了这个问题: