Python webapp Google app引擎:没有名为six的模块

时间:2015-06-27 16:53:59

标签: google-app-engine google-app-engine-python

以下代码应显示input.html中的2个日期,并在output.html中显示月份和年份,但Google应用引擎会返回错误消息,表示缺少模块6,即使我已添加了所有网站我的项目库中的包。

我做错了什么?

import webapp2   
import jinja2   
import os   
import time   
import datetime  
import sys   
from dateutil.rrule import rrule, MONTHLY

sys.path.append(os.path.join(os.path.dirname(__file__), "libs")) 

template_dir = os.path.join(os.path.dirname(__file__), 'templates')  
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
                               autoescape = True)  
def render_str(template, **params):  
    t = jinja_env.get_template(template)  
    return t.render(params)

class MainHandler(webapp2.RequestHandler):  
    def write(self, *a, **kw):  
        self.response.out.write(*a, **kw)

    def render_str(self, template, **params):
        return render_str(template, **params)

    def render(self, template, **kw):
        self.write(self.render_str(template, **kw))

    def get(self):
        self.render('input.html')
    def post(self):
        frmstring=self.request.get('from')
        tostring=self.request.get('to')
        frm=time.strptime(frms,"%Y-%m")
        to=time.strptime(tos,"%Y-%m")
        dates = [dt for dt in rrule(MONTHLY, dtstart=frm, until=to)]
        months_choices = []
        for i in range(1,13):
            months_choices.append(datetime.date(2008, i, 1).strftime('%B'))
        self.render('output.html',dates = dates,months_choices=months_choices)

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

2 个答案:

答案 0 :(得分:5)

您需要在您的环境中提供六个供应商。

运行

pip install -t lib six

然后将这些行添加到apppengine_config.py文件中(或创建它)

# appengine_config.py
from google.appengine.ext import vendor

# Add any libraries install in the "lib" folder.
vendor.add('lib')

有关详细信息,请参阅https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#installing_a_third-party_library

答案 1 :(得分:1)

AppEngine环境不提供six模块。您是否已将其包含在lib/目录中?