我正在使用ndb,但是当我在python中导入appengine模块时我被卡住了。这种情况只发生在我的单元测试中。单元测试位于项目根目录下的 test.py 中。
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.ext import ndb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named appengine.ext
以下是我的 .bash_profile 中与上述相关的内容。
APP_ENGINE_HOME="/Users/xxxxx/google-cloud-sdk/platform/google_appengine/"
export PATH=$PATH:$MYSQL:$M2_HOME/bin:$ANT_HOME/bin:$CATALINA_HOME/bin:$APP_ENGINE_HOME
我在 google_appengine 中有一个名为 Google 的目录,其结构如下
.Gooogle
+-- __init__.py
+-- appengine
| +-- __init__.py
| +-- ext
| +-- ndb
| +-- __init__.py
请帮忙。
最佳答案
在外部使用 appengine 包的最简单方法是利用 dev_appserver 进行设置:
import sys
sys.path.insert(0, '/path/to/google_appengine')
import dev_appserver
dev_appserver.fix_sys_path()
# and then e.g.
from google.appengine.ext import ndb
关于python - 无法导入模块 appengine.ext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25571138/