Reputation: 1321
When I import the httplib2 in quickStart.py and run it using terminal It works.
Now I import quickStart in another file main.py(Google app engine web app python file) and try loading the page via localhost it shows "Import error no module named httplib2" while both files are in the same directory. It shows following error :-
ERROR 2015-10-13 12:41:47,128 wsgi.py:263]
Traceback (most recent call last):
File "C:\Program Files (x86)\google\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files (x86)\google\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Program Files (x86)\google\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "G:\dtuwiki\dtuwiki2\main.py", line 7, in <module>
import quickStart
File "G:\dtuwiki\dtuwiki2\quickStart.py", line 2, in <module>
import httplib2
ImportError: No module named httplib2
INFO 2015-10-13 18:11:47,398 module.py:809] default: "GET / HTTP/1.1" 500 -
main.py
import webapp2
import jinja2
import os
import cgi
import quickStart
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
root_dir = os.path.dirname(__file__)
jinja_env =
jinja2.Environment(loader=jinja2.FileSystemLoader([template_dir,root_dir]),autoescape=True)
def escapeHTML(string):
return cgi.escape(string , quote="True")
class Handler(webapp2.RequestHandler):
def write(self,*a,**kw):
#self.response.write(form %{"error":error})
self.response.out.write(*a,**kw)
def render_str(self,template,**params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self , template ,**kw):
self.write(self.render_str(template,**kw))
quickStart.py
from __future__ import print_function
import httplib2
import os
from apiclient import discovery
import oauth2client
from oauth2client import client
from oauth2client import tools
import datetime
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Google Calendar API Python Quickstart'
def get_credentials():
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'calendar-python-quickstart.json')
store = oauth2client.file.Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatability with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
I also tried following --
$ python -m pip install httplib2
Requirement already satisfied (use --upgrade to upgrade): httplib2 in /usr/local/lib/python2.7/site-packages
Cleaning up...
C:\WINDOWS\system32>python -m pip -V
pip 7.1.2 from C:\Python27\lib\site-packages (python 2.7)
C:\WINDOWS\system32>python -m pip list
google-api-python-client (1.4.2)
httplib2 (0.9.2)
Jinja2 (2.8)
oauth2client (1.5.1)
pip (7.1.2)
uritemplate (0.6)
virtualenv (13.1.2)
Upvotes: 3
Views: 2802
Reputation: 6893
Google App Engine requires that any 3rd party modules be included inside the application source tree in order to deploy it to App Engine. This means that items inside site-packages
will not be imported into an app running under the development SDK and you will see an error similar to what you are experiencing.
Here are the docs on how to include libraries like httplib2
.
The short of it is that you would need to pip install -t some_dir <libname>
and then add some_dir
to your application's path inside of appengine_config.py
Upvotes: 4