Search code examples
pythonsqlalchemygoogle-cloud-sql

What needs to be installed along with google appengine for sqlalchemy / google cloud sql api?


I tried the recommendations in Can SQLAlchemy be used with Google Cloud SQL? to bring up an external connection to google cloud sql using sqlalchemy.

To allow visibility of google appengine packages to my environment, after installing the google appengine sdk, I copied the google directory to site-packages and created a google.pth file which contains single line with './google'. The google packages were then visible.

When I try to do the create_engine call, I get the following exception. Is something missing in my install? How can I correct this?

create_engine('mysql+gaerdbms:///runningdb', connect_args={"fsrcrunning":"fsrcrunningdb"})

C:\Python27\lib\site-packages\sqlalchemy-0.8.0-py2.7-win32.egg\sqlalchemy\engine\__init__.pyc in create_engine(*args, **kwargs)
    330     strategy = kwargs.pop('strategy', default_strategy)
    331     strategy = strategies.strategies[strategy]
--> 332     return strategy.create(*args, **kwargs)
    333
    334

C:\Python27\lib\site-packages\sqlalchemy-0.8.0-py2.7-win32.egg\sqlalchemy\engine\strategies.pyc in create(self, name_or_url, **kwargs)
     62                 if k in kwargs:
     63                     dbapi_args[k] = kwargs.pop(k)
---> 64             dbapi = dialect_cls.dbapi(**dbapi_args)
     65
     66         dialect_args['dbapi'] = dbapi

C:\Python27\lib\site-packages\sqlalchemy-0.8.0-py2.7-win32.egg\sqlalchemy\dialects\mysql\gaerdbms.pyc in dbapi(cls)
     48             return rdbms_apiproxy
     49         else:
---> 50             from google.storage.speckle.python.api import rdbms_googleapi
     51             return rdbms_googleapi
     52

C:\Python27\lib\site-packages\google\storage\speckle\python\api\rdbms_googleapi.py in <module>()
     44         'PYTHONPATH when using this backend.')
     45
---> 46 from apiclient import errors
     47 from apiclient import http
     48 from apiclient import model

ImportError: No module named apiclient

Solution

  • apiclient is part of the google-api-python-client which can be installed via pip install google-api-python-client, although the client is also bundled with the App Engine SDK in the lib directory and is the copy I use. I never move my App Engine install to site-packages but instead add the path to PYTHONPATH inside of .bash_profile, like so (I'm running a Mac):

    export PYTHONPATH=/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine:$PYTHONPATH

    There is also a Google Cloud SDK, which was just released a few weeks ago, which encompasses all the Google Cloud services, including Cloud SQL and App Engine.