我刚刚安装了nltk,现在它无法正常工作,我需要协助找出错误。
我按照[https://pythonprogramming.net/tokenizing-words-sentences-nltk-tutorial/][1]
中的安装指南进行操作通过pip安装
sudo pip install nltk
然后我启动了python并下载了所有组件
# python3
>>> import nltk
>>> nltk.download()
这很有用,它下载了所有组件(我选择了所有组件)。之后我觉得我很高兴。然而,然后我去写了我的第一个脚本,并且在导入nltk的第一行出错了。
现在,当我打开python解释器时,我得到了
# python3
>>> import nltk
"2016-03-02 04:34:03,630","regex.py","ERROR","There is a problem with your SQL query: SELECT regex, regex_id FROM regex WHERE type = 'date'"
Traceback (most recent call last):
File "/home/nick/booze-dev/regex.py", line 10, in <module>
cursor.execute(SQL) # Execute SQL
NameError: name 'cursor' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import *
File "/usr/local/lib/python3.4/dist-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/usr/local/lib/python3.4/dist-packages/nltk/chunk/api.py", line 15, in <module>
from nltk.chunk.util import ChunkScore
File "/usr/local/lib/python3.4/dist-packages/nltk/chunk/util.py", line 13, in <module>
from nltk.tag.mapping import map_tag
File "/usr/local/lib/python3.4/dist-packages/nltk/tag/__init__.py", line 63, in <module>
from nltk.tag.sequential import (SequentialBackoffTagger, ContextTagger,
File "/usr/local/lib/python3.4/dist-packages/nltk/tag/sequential.py", line 25, in <module>
from nltk.classify import NaiveBayesClassifier
File "/usr/local/lib/python3.4/dist-packages/nltk/classify/__init__.py", line 98, in <module>
from nltk.classify.textcat import TextCat
File "/usr/local/lib/python3.4/dist-packages/nltk/classify/textcat.py", line 47, in <module>
import regex as re
File "/home/nick/booze-dev/regex.py", line 14, in <module>
sys.exit("Aborting script execution")
NameError: name 'sys' is not defined
第一次运行导入并执行nltk.download()时,我没有收到错误,所以我不明白为什么我现在就得到它。
我尝试以root身份和普通用户身份执行python,并得到同样的错误。
如果我检查我的sys.path
>>> import sys
>>> sys.path
['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']
我可以在/usr/local/lib/python3.4/dist-packages下找到nltk:
# ls /usr/local/lib/python3.4/dist-packages | grep nltk
nltk
nltk-3.1.egg-info
所以它应该可用。那么为什么我现在导入时会出现错误?