我正在尝试在 Google App Engine 中导入 NLTK 库它给出错误,我创建了另一个模块“testx.py”并且这个模块没有错误但我不知道为什么 NLTK 不起作用。
我的代码 nltk_test.py
导入 webapp2 导入路径转换器 导入 testx 导入 nltk 类 MainPage(webapp2.RequestHandler): 定义获取(自我): #self.response.headers['Content-Type'] = 'text/plain' self.response.write("测试") 类 nltkTestPage(webapp2.RequestHandler): 定义获取(自我): text = nltk.word_tokenize("现在是完全不同的东西") self.response.write(testx.test("Hellooooo")) 应用程序 = webapp2.WSGIApplication([ ('/', MainPage), ('/nltk', nltkTestPage), ],调试=真)
testx.py 代码
定义测试(txt): 返回长度(txt)
path_changer.py 代码
导入操作系统 导入系统 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'nltk')) sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'new'))
应用程序.yaml
应用程序:nltkforappengine 版本:0-1 运行时:python27 api_version: 1 线程安全:真 处理程序: - 网址:/.* 脚本:nltk_test.application - 网址:/nltk.* 脚本:nltk_test.application 图书馆: - 名称:numpy 版本:“1.6.1”
此代码工作正常当我注释import nltk和nltk相关代码时,我认为NLTK没有导入,请帮我解决这个问题,谢谢