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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15783783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:59:40  来源:igfitidea点击:

python import error "No module named appengine.ext"

pythongoogle-app-engine

提问by Rajeev Das

after runing this code,I found import error:-

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

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()

how to use google.apengine.ext

如何使用 google.apengine.ext

采纳答案by J?rg Beyer

It looks like the App Engine SDK is not installed, or at least the Python runtime cannot find it.

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

read and follow the instructions here: https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python

阅读并遵循此处的说明:https: //cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python

They tell you, how to install App Engine SDK for Python.

他们告诉您如何安装适用于 Python 的 App Engine SDK。

回答by Xavi Gonzalvo

Try:

尝试:

import google
print google.__path__

to see what exactly you're importing.

看看你到底要导入什么。

回答by varun

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']

this solves the problems for me

这为我解决了问题

回答by Paul Bendevis

I had this same issue because I pip installed gcloud before downloading and installing the SDK. The pip install created a python package google which didn't contain the appengine submodule (which is found in the SDK folder). I uninstalled the gcloud and related packages. Then just pip installed the google-cloud-bigquery which is the only package I needed from gcloud. Everything works fine now.

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

回答by makkasi

check if you named some file google.py :) in the same package, because this can shadow the import of google.appengine.ext. I had the same error:

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

python import error “No module named appengine.ext”

and deleteting the file solved the problem.

并删除文件解决了问题。

回答by Ash

I faced similar error while calling Google Analytics API using AWS Lambda.

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

Workaround from (Schweigi1) helped me.

(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

Usage:

用法:

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

Hope this helps someone who is facing this issue in AWS Lambda.

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

回答by Israel

First possible reason:

第一个可能的原因:

you don't install the python library in google cloud sdk, so you can run in cmd (as administrator):

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

gcloud components install app-engine-python.

gcloud components install app-engine-python.

Second possible reason:

第二个可能的原因:

your IDE is not success get into google libraries, they exist in:

你的 IDE 没有成功进入谷歌库,它们存在于:

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

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

or in:

或在:

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

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

You can see in attached link explain how to add these libraries to IDE external libraries: https://stackoverflow.com/a/24206781/8244338

您可以在附加链接中看到解释如何将这些库添加到 IDE 外部库:https: //stackoverflow.com/a/24206781/8244338

回答by Sanit

I got this error in python:

我在python中遇到了这个错误:

from google.appengine.api import search
ImportError: No module named appengine.api

I thought this would be something along the similar lines of what is happening in this thread.

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

So, my solution was to run "dev_appserver.py 'your yaml file' ". I got this solution following the below links:

所以,我的解决方案是运行“dev_appserver.py 'your yaml file'”。我通过以下链接得到了这个解决方案:

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

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

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

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

Hope this helps!

希望这可以帮助!