如何在Google App Engine上安装googlemaps模块

问题描述 投票:2回答:2

我正在使用Python3.7运行时并使用命令将googlemaps模块安装到lib文件夹中

$ python -m pip --upgrade install -t lib/ googlemaps

它在当地运作良好。我将我的烧瓶项目部署到Google云中,我在appengine_config.py中定义了供应商,如下所示:

import os
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))

但是当项目部署在谷歌引擎上时,我收到此错误:

 import googlemaps  ModuleNotFoundError: No module named 'googlemaps'

有什么帮助吗?

python google-maps google-app-engine google-cloud-platform
2个回答
0
投票

你的lib文件夹有__init__.py吗?

它需要一个,因为lib文件夹被视为一个包

https://docs.python.org/3/tutorial/modules.html#packages

但如果可以的话,你应该使用像@Dustin推荐的requirements.txt。我已经在python2环境中工作多年了,我的lib文件夹已经变得笨拙。


2
投票

Python 3.7是一个“惯用的”Python运行时。除此之外,它意味着您不需要将依赖项与应用程序捆绑在一起,就像您以前必须为2.7运行时所做的那样。

相反,您应该在其中指定包含名称的requirements.txt文件,例如:

googlemaps==3.0.2

下次部署应用时,将依赖此依赖项。有关详细信息,请参阅“Specifying Dependencies”。

© www.soinside.com 2019 - 2024. All rights reserved.