0

我正在尝试用 python 编写一个 Google App Engine 程序,当我尝试部署它时,我在启动器的日志中不断收到错误消息

ImportError: No module named pygeocoder

当我在用于 App Engine 程序的目录中时,在 Python 命令行中键入“import pygeocoder”,就可以了。我对此有点菜鸟,不知道如何导入它。这是我的代码

import webapp2
import cgi
import jinja2
import os
import time
from pygeocoder import Geocoder 
jinja_environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

class MainPage(webapp2.RequestHandler):
  def get(self):
    template = jinja_environment.get_template('index.html')
    self.response.out.write(template.render())

class Map(webapp2.RequestHandler):
  def post(self):

    line = cgi.escape(self.request.get('line_name'))
    self.getPositions(line)
def getPositions(self, line):
    current=str(time.mktime(time.gmtime())) #Gets current time for web feed
    stations = urllib2.urlopen('http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=sf-muni&r=' + line + '&t='+current)
    tree=ET.parse(stations)
    root=tree.getroot() 
    vehid=list()
    latitude=list()
    longitude=list()
    head=list()
    spd=list()
    address=list()
    for info in root.iter('vehicle'):
        veh_id=info.get('id')
        lat   =float(info.get('lat'))
        lon   =float(info.get('lon'))
        address1=Geocoder.reverse_geocode(lat, lon)
        street=str(address1[0])
        heading = info.get('heading')
        speed=info.get('speedKmHr')
        vehid.append(veh_id)
        latitude.append(lat)
        longitude.append(lon)
        head.append(heading)
        spd.append(speed)
        address.append(street)
    template_values={
    'latitude': latitude,
    'longitude': longitude,
    'heading': head,
    'speed': spd,
    'address':address,
    'vehid': vehid
    }

    template = jinja_environment.get_template('map.html')
    self.response.out.write(template.render(template_values))
app = webapp2.WSGIApplication([('/', MainPage),
                          ('/map', Map)],
                          debug=True)

这是我的 app.yaml 文件:

application: munipositions
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
script: munipositions.app

libraries:
- name: jinja2
version: latest
4

1 回答 1

0

谢谢,我只需要将它放在我的应用程序目录中,它现在就可以工作了。

于 2013-03-20T03:28:58.280 回答