python导入错误“没有名为appengine.ext的模块”

时间:2013-04-03 09:36:31

标签: python google-app-engine

运行此代码后,我发现导入错误: -

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication([('/', MainPage)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

如何使用google.appengine.ext

8 个答案:

答案 0 :(得分:17)

看起来没有安装App Engine SDK,或者至少Python运行时找不到它。

阅读并按照此处的说明操作:https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python

他们告诉您,如何安装App Engine SDK for Python。

答案 1 :(得分:15)

import sys
sys.path.insert(1, '/Users/<username>/google-cloud-sdk/platform/google_appengine')
sys.path.insert(1, '/Users/<username>/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')
sys.path.insert(1, 'lib')

if 'google' in sys.modules:
    del sys.modules['google']

这解决了我的问题

答案 2 :(得分:8)

尝试:

import google
print google.__path__

了解您正在导入的内容。

答案 3 :(得分:2)

我遇到了同样的问题,因为在下载和安装SDK之前我已经安装了gcloud。 pip install创建了一个python包google,它不包含appengine子模块(可以在SDK文件夹中找到)。我卸载了gcloud和相关的软件包。然后只是pip安装了google-cloud-bigquery,这是我需要的唯一一个来自gcloud的软件包。现在一切都很好。

答案 4 :(得分:1)

第一个可能的原因:

您没有在google cloud sdk中安装python库,因此可以在cmd中运行(以管理员身份):

gcloud components install app-engine-python

第二个可能的原因:

您的IDE不能成功进入Google库,它们存在于:

C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine

或在以下位置:

C:\Users\[your user]\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine

您可以在附件的链接中看到有关如何将这些库添加到IDE外部库的说明:https://stackoverflow.com/a/24206781/8244338

答案 5 :(得分:0)

检查您是否在同一个软件包中命名了某个文件google.py :),因为这会影响google.appengine.ext的导入。我有同样的错误:

python import error “No module named appengine.ext”

并删除文件解决了问题。

答案 6 :(得分:0)

使用AWS Lambda调用Google Analytics API时遇到类似的错误。

(Schweigi 1)的解决方法帮助了我。

import googleapiclient
from googleapiclient.discovery_cache.base import Cache

class MemoryCache(Cache):
    _CACHE = {}

    def get(self, url):
        return MemoryCache._CACHE.get(url)

    def set(self, url, content):
        MemoryCache._CACHE[url] = content

用法:

service = googleapiclient.discovery.build("analyticsreporting", "v4", http=http, credentials=credentials,cache=MemoryCache())

希望这可以帮助在AWS Lambda中面临此问题的人。

答案 7 :(得分:0)

我在python中遇到此错误:

@Bean
    fun graphQL(schema: GraphQLSchema): GraphQL {
        return GraphQL.newGraphQL(schema)
                .queryExecutionStrategy(AsyncExecutionStrategy(CustomExceptionHandler()))
                .mutationExecutionStrategy(AsyncSerialExecutionStrategy(CustomExceptionHandler()))
                .build()
    }

我认为这与该线程中发生的事情类似。

因此,我的解决方案是运行“ dev_appserver.py'您的Yaml文件'”。我通过以下链接获得了该解决方案:

1)https://cloud.google.com/appengine/docs/standard/python/tools/using-local-server

2)https://www.youtube.com/watch?v=BdqUY8lCuBI

希望这会有所帮助!