-1

在简单导入 httplib2 出现一些问题后(请参阅我的帖子),我导入 gflags 时遇到了另一个问题。

事实上,在开发服务器上,我第一次启动应用程序时遇到了 ImportError。但是,如果我刷新浏览器,这些应用程序就会工作!如果我查看日志,我可以看到:

...
ImportError: No module named gflags
[App Instance] [0] [dev_appserver.py:2891] INFO "GET / HTTP/1.1" 500 -
[App Instance] [0] [py_zipimport.py:148] INFO zipimporter('/usr/lib/python2.5/site-packages/setuptools-0.6c11-py2.5.egg', '')
[App Instance] [0] [py_zipimport.py:148] INFO zipimporter('/usr/lib/python2.5/site-packages/python_gflags-2.0-py2.5.egg', '')

因此,应用程序在开发服务器上刷新后可以工作,但在 apppot 上载后它根本不工作:

<type 'exceptions.ImportError'>: No module named gflags
Traceback (most recent call last):
  File "/base/data/home/apps/s~yoyocontacts/2.358733066847060730/main.py", line 33, in <module>
from apiclient.discovery import build
  File "/base/data/home/apps/s~yoyocontacts/2.358733066847060730/apiclient/discovery.py", line 48, in <module>
from apiclient.http import HttpRequest
  File "/base/data/home/apps/s~yoyocontacts/2.358733066847060730/apiclient/http.py", line 47, in <module>
from model import JsonModel
  File "/base/data/home/apps/s~yoyocontacts/2.358733066847060730/apiclient/model.py", line 27, in <module>
import gflags

我的应用程序是这个HelloWorld

lrwxrwxrwx 1 yoyo   77 2012-05-06 16:24 apiclient -> /home/yoyo/dev/outils/google_appengine/lib/google-api-python-client/apiclient/
-rw-r--r-- 1 yoyo  169 2012-05-06 16:19 app.yaml
-rw-r--r-- 1 yoyo  358 2012-05-06 15:20 client_secrets.json
lrwxrwxrwx 1 yoyo   60 2012-05-07 12:12 gflags -> /home/yoyo/dev/outils/google_appengine/lib/python-gflags/
-rw-r--r-- 1 yoyo  554 2012-03-02 20:00 grant.html
lrwxrwxrwx 1 yoyo   60 2012-05-06 16:20 httplib2 -> /home/yoyo/dev/outils/google_appengine/lib/httplib2/httplib2/
-rw-r--r-- 1 yoyo  471 2012-03-02 20:00 index.yaml
-rw-r--r-- 1 yoyo 3,4K 2012-05-07 11:45 main.py
lrwxrwxrwx 1 yoyo   56 2012-05-06 16:24 oauth2 -> /home/yoyo/dev/outils/google_appengine/lib/oauth2/oauth2/
lrwxrwxrwx 1 yoyo   80 2012-05-07 10:59 oauth2client -> /home/yoyo/dev/outils/google_appengine/lib/google-api-python-client/oauth2client/
-rwxr-xr-x 1 yoyo  163 2012-05-07 11:14 run*
-rwxr-xr-x 1 yoyo  115 2012-05-07 11:50 upload*
lrwxrwxrwx 1 yoyo   79 2012-05-06 16:24 uritemplate -> /home/yoyo/dev/outils/google_appengine/lib/google-api-python-client/uritemplate/
-rw-r--r-- 1 yoyo  102 2012-03-02 20:00 welcome.html

我的问题:

  • 为什么 zipimporter 仅在刷新后才有效?
  • 如何在 apppot 上修复此错误?
4

1 回答 1

2

谢谢@greg。

我添加__init__.py了 withimport gflags然后我修改apiclient/model.py了 withfrom gflags import gflags而不是import gflags.

于 2012-05-08T14:41:59.323 回答