我已經安裝了CherryPy的在Mac上的Apache服務器作爲我的網絡framework.I打算暴露NLTK涉及某些服務時給出了一個錯誤。我也遇到了500個內部錯誤。在互聯網上搜索解釋「AttributeError的:‘模塊’對象有沒有屬性‘詞’」,在系統Python和NLTK作爲循環依賴issue.I嫌疑版本的區別。CherryPy的使用NLTK(自然語言工具包)
我是新來的Python和我的調試技巧真的poor.Kindly幫助
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'
你需要'進口nltk.word'。 – Blender
感謝Blender.Still沒有解決。在python終端上,我可以導入nltk,但我得到這個:Traceback(最近調用最後一個): 文件「hello.py」,第2行,在 import nltk.word 導入錯誤:沒有模塊名爲話,如果我使用進口nltk.word –
user2261494