google-app-engine : ImportError httplib2 in google api python client hello world

两盒软妹~` 提交于 2019-12-13 01:24:47

问题


I just downloaded the Google App Engine SDK for python (google_appengine_1.6.5.zip) and i try to launch an example from google-api-python-client (appengine) :

$ tree
.
|-- app.yaml
|-- client_secrets.json
|-- grant.html
|-- index.yaml
|-- main.py
`-- welcome.html

I launch dev server : : ./dev_appserver.py /home/yoyo/dev/projets/yoyocontacts/ --backends --clear_datastore --high_replication

But when i launched application in my browser, i have the following error : ImportError: No module named httplib2.

My plateform is Ubuntu 10.04.4 LTS with Python 2.6.5 and an import of httplib2 with Python cli works fine. And there is httplib2 in google-appengine directory :

$ locate httplib2|grep appengine

/home/yoyo/dev/outils/google_appengine/lib/httplib2
/home/yoyo/dev/outils/google_appengine/lib/httplib2/httplib2
/home/yoyo/dev/outils/google_appengine/lib/httplib2/httplib2/LICENSE
/home/yoyo/dev/outils/google_appengine/lib/httplib2/httplib2/OWNERS
/home/yoyo/dev/outils/google_appengine/lib/httplib2/httplib2/__init__.py
... 

How resolve properly this import problem ?

I know that i can add httplib2 in my application directory but it's not elegant :

$tree
...
|-- httplib2
|   |-- cacerts.txt
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- iri2uri.py
|   |-- iri2uri.pyc
|   |-- socks.py
|   |-- socks.pyc 

I finally added the correct symlinks : (thanks to @Thanasis)

$ll
total 36K
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  267 2012-05-07 12:28 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 -> /usr/lib/python2.5/site-packages/python_gflags-2.0-py2.5.egg
-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*
drwxr-xr-x 3 yoyo 4,0K 2012-05-07 12:27 static/
-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

Now, i have to deal with a new problem with gflags.


回答1:


here is a solution.

  • make a temporary directory somewhere out of the source tree.
  • cd to the directory and unzip /usr/lib/python2.5/site-packages/python_gflags-2.0-py2.5.egg
  • copy *.py to the source directory.



回答2:


Most third party libraries need to be included as part of your project. The easiest way to do this (Adapted from the App Engine documentation) is:

In your project directory (the one with app.yaml):

$ mkdir lib
$ pip install -t lib/ httplib2

Then create a new file named appengine_config.py in the same directory:

# appengine_config.py
vendor.add('lib')

If you have multiple third party dependencies, but their names in a requirements.txt and then use

pip install -t lib/ -r requirements.txt


来源:https://stackoverflow.com/questions/10471111/google-app-engine-importerror-httplib2-in-google-api-python-client-hello-world

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!