简体   繁体   English

在不使用dev_appserver.py的情况下从google.appengine.api导入memcache

[英]Importing memcache from google.appengine.api without using dev_appserver.py

According to the Google AppEngine documentation, one should import memcache like this: 根据Google AppEngine文档,应该像这样导入memcache:

from google.appengine.api import memcache

I'm using a virtualenv and I'm creating some scripts to test a library I created for AppEngine. 我正在使用virtualenv,我正在创建一些脚本来测试我为AppEngine创建的库。 I am not trying to test a website, I am trying to test a specific library that uses memcache. 我不是要测试一个网站,我正在尝试测试一个使用memcache的特定库。 Evidently, without using dev_appserver.py I get an ImportError: No module named google.appengine.api . 显然,不使用dev_appserver.py我得到一个ImportError: No module named google.appengine.api

I had a look at the source of dev_appserver.py but first I'd like to know if there is a simpler solution that would not require rewriting PATH as Google does. 我查看了dev_appserver.py来源 ,但首先我想知道是否有一个更简单的解决方案,不需要像谷歌那样重写PATH。

Thanks! 谢谢!

For testing purposes we always create a local checkout of the AppEngine library like this: 出于测试目的,我们总是创建一个AppEngine库的本地签出,如下所示:

GAE_VERSION=1.6.2

resttest: dependencies lib/google_appengine/google/__init__.py
    sh -c "PYTHONPATH=lib/google_appengine/ python tests/resttest.py --hostname=$(TESTHOST) --credentials-user=$(CREDENTIALS_USER)"

lib/google_appengine/google/__init__.py:
    curl -s -O http://googleappengine.googlecode.com/files/google_appengine_$(GAE_VERSION).zip
    unzip -q google_appengine_$(GAE_VERSION).zip
    rm -Rf lib/google_appengine
    mv google_appengine lib/
    rm google_appengine_$(GAE_VERSION).zip

dependencies:
    git submodule update --init

There is no simple solution, at the minimum you'll have to setup your Python paths. 没有简单的解决方案,至少您必须设置Python路径。 That's all the dev_appserver wrapper you linked to does. 这就是你链接到的所有dev_appserver包装器。 For testing code / libraries I usually write a simple wrapper that does basically the same thing as dev_appserver is doing. 为了测试代码/库,我通常编写一个简单的包装器,它与dev_appserver的功能基本相同。

In some cases you'll actually need to go a step further and initialize the stubs as well. 在某些情况下,您实际上还需要更进一步并初始化存根。 If you follow through the dev_appserver code, you'll be able to see how this is done. 如果您遵循dev_appserver代码,您将能够看到这是如何完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM