使用终端的 Google App Engine 交互式控制台
按照本页上的说明进行操作,使用 remote_api 远程访问数据存储区:
我编辑了 app.yaml
包含这些行:
builtins:
- remote_api: on
我打开了一个终端:
$ cd /path/to/app
$ python2.5 /usr/local/google_appengine/remote_api.shell.py\
-s localhost:8082 -p /_ah/remote_api
在我的应用程序文件夹结构的根部,我有一个名为 foobar.py
的模块,以及一个名为数据模型
。获得对 remote_api
Python 解释器的访问权限后,我尝试以下几行:
import foobar
import data_models
但出现错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named foobar
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named data_models
如何通过终端访问交互式控制台?我错过了什么吗?即使我登录云服务器也会发生同样的情况:
$ python2.5 /usr/local/google_appengine/remote_api.shell.py\
-s my-app.appspot.com -p /_ah/remote_api
Following instructions on this page, Accessing the datastore remotely with remote_api:
I edited app.yaml
to include these lines:
builtins:
- remote_api: on
I opened up a Terminal:
$ cd /path/to/app
$ python2.5 /usr/local/google_appengine/remote_api.shell.py\
-s localhost:8082 -p /_ah/remote_api
At the root of my app folder structure, I have a module named foobar.py
, as well as a package named data_models
. After gaining access to the remote_api
Python interpreter, I try the following lines:
import foobar
import data_models
But I get an error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named foobar
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named data_models
How do I access the interactive console through the Terminal? Am I missing something? The same thing happens even if I login to the cloud server:
$ python2.5 /usr/local/google_appengine/remote_api.shell.py\
-s my-app.appspot.com -p /_ah/remote_api
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
remote_api
只是使得从本地任务到 App Engine 应用的远程实例进行 RPC 调用成为可能。 Python 控制台本身仍然是本地的,您所做的一切都在本地执行。这意味着您尝试导入的任何模块都必须存在于您的本地计算机上,您的 Python 实例可以在某个地方找到它们 - 可能通过将应用程序的目录添加到PYTHONPATH
中,如下所示:remote_api
just makes it possible to make RPC calls from a local task to a remote instance of an App Engine app. The Python console itself is still local, and everything you do executes locally. That means that any modules you try and import must exist on your local machine, somewhere your Python instance can find them - probably by adding your app's directory toPYTHONPATH
, like this:我将以下行添加到我的
.bash_profile
中,这样我就不必每次启动终端时都编辑PYTHONPATH
了。I added the following lines to my
.bash_profile
so that I won't have to editPYTHONPATH
every time I fire up the Terminal.看来remote_api与您的应用程序位于不同的路径中,因此curpwd是remote_api的路径,因此您的应用程序的代码不可用
It seems that the remote_api is in a different path than your app so it curpwd is that of the remote_api so your app's code is not available