【发布时间】:2014-07-29 05:39:32
【问题描述】:
我正在尝试使用 Flask 在 Heroku 上运行 webapp。 webapp 是用 Python 编写的,带有 NLTK(自然语言工具包库)。
其中一个文件具有以下标题:
import nltk, json, operator
from nltk.corpus import stopwords
from nltk.tokenize import RegexpTokenizer
当调用带有停用词代码的网页时,会产生以下错误:
LookupError:
**********************************************************************
Resource 'corpora/stopwords' not found. Please use the NLTK
Downloader to obtain the resource: >>> nltk.download()
Searched in:
- '/app/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
**********************************************************************
使用的确切代码:
#remove punctuation
toker = RegexpTokenizer(r'((?<=[^\w\s])\w(?=[^\w\s])|(\W))+', gaps=True)
data = toker.tokenize(data)
#remove stop words and digits
stopword = stopwords.words('english')
data = [w for w in data if w not in stopword and not w.isdigit()]
当stopword = stopwords.words('english') 被注释掉时,Heroku 上的 webapp 不会产生查找错误。
代码在我的本地计算机上正常运行。我已经使用
在我的计算机上安装了所需的库pip install requirements.txt
当我在我的电脑上测试代码时,Heroku 提供的虚拟环境正在运行。
我也尝试了两个不同来源提供的 NLTK,但 LookupError 仍然存在。我使用的两个来源是:
http://pypi.python.org/packages/source/n/nltk/nltk-2.0.1rc4.zip
https://github.com/nltk/nltk.git
【问题讨论】:
标签: python python-2.7 heroku flask nltk