简体   繁体   English

google-app-engine:google api python客户端hello world中的ImportError httplib2

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

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 ) : 我刚刚下载了适用于python的Google App Engine SDK(google_appengine_1.6.5.zip),然后尝试从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 我启动开发服务器:: ./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 . 但是,当我在浏览器中启动应用程序时,出现以下错误: 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. 我的平台是带有Python 2.6.5的Ubuntu 10.04.4 LTS,并且带有Python cli的httplib2导入都可以正常工作。 And there is httplib2 in google-appengine directory : google-appengine目录中有httplib2:

$ 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 : 我知道我可以在应用程序目录中添加httplib2,但它并不优雅:

$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) 我终于添加了正确的符号链接:(感谢@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 . 现在,我不得不用gflags处理一个新问题。

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 cd到目录并解压缩/usr/lib/python2.5/site-packages/python_gflags-2.0-py2.5.egg
  • copy *.py to the source directory. 将* .py复制到源目录。

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: 最简单的方法(从App Engine文档中改编而成)是:

In your project directory (the one with app.yaml ): 在您的项目目录(带有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的新文件:

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

If you have multiple third party dependencies, but their names in a requirements.txt and then use 如果您有多个第三方依赖项,但是它们的名称在requirements.txt中,然后使用

pip install -t lib/ -r requirements.txt

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

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