我正在尝试做部分字符串标记以在 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"
编写 test.py 与
import nltk
在里面- 部署,运行并得到以下错误(numpy错误已解决,但我得到了一个新错误):
Traceback(最近一次调用最后):文件“/base/data/home/apps/s~domain/1.359540170137090086/dynamic/test.py”,第 4 行,在 import nltk 文件“/base/data/home/apps/s ~domain/1.359540170137090086/nltk/ init .py”,第 116 行,在 import ccg 文件中“/base/data/home/apps/s~domain/1.359540170137090086/nltk/ccg/init .py ”,第 14 行,来自 nltk .ccg.combinator import (UndirectedBinaryCombinator, DirectedBinaryCombinator, File "/base/data/home/apps/s~domain/1.359540170137090086/nltk/ccg/combinator.py", 第 8 行, in from nltk.parse import ParserI File "/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 行,在 if os.path.expanduser('~/') != '~ /': path += [ File "/base/python27_runtime/python27_dist/lib/python2.7/posixpath.py", line 259, in expanduser 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']