nltk.tokenize从Shell正确执行但是作为脚本文件获取错误

时间:2016-04-11 01:49:24

标签: python nltk

我在mac os 10.11.4中使用python idle 3.5.1 我正在python shell中直接执行以下代码,它完美地运行

>>> import nltk
>>> from nltk.tokenize import sent_tokenize, word_tokenize
>>> sample_sentence = "Hi, this is a sample sentence. Python is great"
>>> sample_sentence
'Hi, this is a sample sentence. Python is great'
>>> sent_tokenize(sample_sentence)
['Hi, this is a sample sentence.', 'Python is great']
>>> 

但是我保存与脚本文件相同的代码以及执行时 我收到一个错误。

import nltk
from nltk.tokenize import sent_tokenize, word_tokenize
sample_sentence = "Hi, this is a sample sentence. Python is great"
print(sent_tokenize(sample_sentence))

当我运行此脚本文件时,我收到以下错误

  

RESTART:/Users/Documents/sample_codes/python3_sample.py Traceback   (最近一次调用最后一次):文件   " /Users/Documents/sample_codes/python3_sample.py" ;,第2行,在   从nltk.tokenize import sent_tokenize,word_tokenize ImportError:No   模块名为' nltk.tokenize&#39 ;; ' NLTK'不是包

我不明白这一点。请帮忙

感谢。

0 个答案:

没有答案