NLTK 导入错误 [英] NLTK import error

查看:20
本文介绍了NLTK 导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 和 NLTK 的新手.我一直在努力寻找解决问题的方法,但还没有找到,希望有人能帮助我.

I'm new to Python and NLTK. I've been trying to find a solution to my problem but have not found one yet and was hoping someone could help me.

我目前运行的是 64 位 Windows 8.我已经按照 NLTK 网站 (http://www.nltk.org/install.html).我可能首先安装了 64 位版本的 Python,但已将其删除并重新安装 32 位版本的 Python.现在我遇到了以下问题:

I'm currently running 64bit Windows 8. I've followed the instruction in the NLTK website (http://www.nltk.org/install.html). I might have installed a 64bit version Python in the first place but have removed it and reinstall 32bit version Python. Now I'm having the following problem:

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [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:Python27libsite-packages
ltk\__init__.py", line 117, in <module>
from nltk.align import *
  File "C:Python27libsite-packages
ltkalign\__init__.py", line 15, in <module>
from nltk.align.ibm1 import IBMModel1
  File "C:Python27libsite-packages
ltkalignibm1.py", line 18, in <module>
    from nltk.corpus import comtrans
  File "C:Python27libsite-packages
ltkcorpus\__init__.py", line 64, in <module>
    from nltk.tokenize import RegexpTokenizer
  File "C:Python27libsite-packages
ltk	okenize\__init__.py", line 62, in <module>
    from nltk.data              import load
  File "C:Python27libsite-packages
ltkdata.py", line 74, in <module>
    if os.path.expanduser('~/') != '~/':
  File "C:Python27lib
tpath.py", line 310, in expanduser
    return userhome + path[i:]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xac in position 9: ordinal not in range(128)
>>> 

有什么想法吗?

推荐答案

我通过更改非 Unicode 程序的操作系统区域设置来解决此问题:

I solve this by changing my operating system locale for non-Unicode programs:

1 – 进入控制面板

2 – 单击时钟、语言和区域"

2 – Click "Clock, Language and Region"

3 – 单击区域和语言选项"

3 – Click "Regional and Language Options"

4 – 进入管理"选项卡

4 – Go under "Administrative" tab

5 – 显示当前系统区域设置(对于非 Unicode),要更改它,请单击更改系统区域设置"

5 – current system locale (for non-Unicode) is displayed, to change it click "Change system locale"

6 – 然后选择英语!重启后,大功告成!

6 – Then just choose English! After a reboot, done!

这篇关于NLTK 导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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