我已经在 mac 上安装了一个 Apache 服务器,并以cherrypy 作为我的 web 框架。我打算公开某些涉及 nltk 的服务。我在做同样的事情时收到 500 个内部错误。互联网上的搜索将“AttributeError:'module'对象没有属性'word'”解释为循环依赖问题。我怀疑系统python和nltk的版本差异。
我是 Python 新手,我的调试技能真的很差。请帮忙
import cherrypy
import nltk
class HelloWorld :
def index(self) :
return "Hello world !"
index.exposed=True
def printHappy(self,age) :
return age
printHappy.exposed=True
def fNouns(self,string):
text = nltk.word.tokenize(string)
nounTag=nltk.pos_Tag(text)
return nounTag
fNouns.exposed=True
cherrypy.quickstart(HelloWorld())
当我尝试使用它访问它时http://localhost:8080/fNouns/hey
,我收到以下错误(但是http://localhost:8080/printHappy/1234
有效!!)
500 Internal Server Error
服务器遇到了一个意外情况,导致它无法完成请求。
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cpdispatch.py", line 34, in __call__
return self.callable(*self.args, **self.kwargs)
File "hello.py", line 14, in fNouns
text = nltk.word.tokenize(string)
AttributeError: 'module' object has no attribute 'word'