【发布时间】:2012-06-14 00:20:46
【问题描述】:
我正在尝试在 Google App Engine 上进行部分字符串标记以提取 Python 中句子的名词。到目前为止,我已经尝试使用 nltk 库。但我无法让 nltk 在 GAE 中工作。错误消息抱怨缺少 numpy 模块。
这个人也有同样的问题: https://groups.google.com/forum/?fromgroups#!topic/nltk-users/2nWZtLgFyvI
我找不到关于如何在 GAE 上运行 nltk 或在 GAE 上运行的替代 POS 标记器的明确说明
编辑:
我试图让 nltk 工作的步骤(我在 osx 10.7 上):
- 通过终端“easy_install nltk”安装nltk
- 将 nltk 复制到 appengine 项目的根目录 /Library/Python/2.7/site-packages/nltk-2.0.1-py2.7.egg/nltk/
-
将以下设置添加到 app.yaml:
runtime: python27 threadsafe: false libraries: name: numpy version: "latest" 用
import nltk编写test.py- 部署、运行并得到以下错误(numpy错误已解决,但我得到一个新错误):
Traceback(最近一次调用最后一次):文件 "/base/data/home/apps/s~domain/1.359540170137090086/dynamic/test.py", 第 4 行,在 导入 nltk 文件 "/base/data/home/apps/s~domain/1.359540170137090086/nltk/init.py", 第 116 行,在 导入ccg文件“/base/data/home/apps/s~domain/1.359540170137090086/nltk/ccg/init.py”, 第 14 行,在 从 nltk.ccg.combinator 导入(UndirectedBinaryCombinator,DirectedBinaryCombinator,文件 "/base/data/home/apps/s~domain/1.359540170137090086/nltk/ccg/combinator.py", 第 8 行,在 从 nltk.parse 导入 ParserI 文件“/base/data/home/apps/s~domain/1.359540170137090086/nltk/parse/init.py”, 第 68 行,在 从 nltk.parse.util 导入 load_parser、TestGrammar、extract_test_sentences 文件 "/base/data/home/apps/s~domain/1.359540170137090086/nltk/parse/util.py", 第 15 行,在 从 nltk.data 导入加载文件“/base/data/home/apps/s~domain/1.359540170137090086/nltk/data.py”, 第 75 行,在 如果 os.path.expanduser('~/') != '~/': path += [ File "/base/python27_runtime/python27_dist/lib/python2.7/posixpath.py", 第 259 行,在扩展用户中 import pwd ImportError: No module named pwd
以下内容来自 nltk/data.py(第 75 行左右):
######################################################################
# Search Path
######################################################################
path = []
"""A list of directories where the NLTK data package might reside.
These directories will be checked in order when looking for a
resource in the data package. Note that this allows users to
substitute in their own versions of resources, if they have them
(e.g., in their home directory under ~/nltk_data)."""
# User-specified locations:
path += [d for d in os.environ.get('NLTK_DATA', '').split(os.pathsep) if d]
if os.path.expanduser('~/') != '~/': path += [
os.path.expanduser('~/nltk_data')]
# Common locations on Windows:
if sys.platform.startswith('win'): path += [
r'C:\nltk_data', r'D:\nltk_data', r'E:\nltk_data',
os.path.join(sys.prefix, 'nltk_data'),
os.path.join(sys.prefix, 'lib', 'nltk_data'),
os.path.join(os.environ.get('APPDATA', 'C:\\'), 'nltk_data')]
# Common locations on UNIX & OS X:
else: path += [
'/usr/share/nltk_data',
'/usr/local/share/nltk_data',
'/usr/lib/nltk_data',
'/usr/local/lib/nltk_data']
【问题讨论】:
标签: google-app-engine nltk pos-tagger