jozxyqk
jozxyqk

Reputation: 17364

Google app engine, cloud sql, and django: no rdbms backend module

I've been following a number of tutorials on setting up google app engine (GAE) with their cloud SQL and django. The conclusion I've reached is most of them get you to install a local copy of python and all the libs. Some even fail to mention they assume you'll be using a local SQL server for testing/development.

Firstly, python modules you install locally don't magically get uploaded to GAE. Either you use existing GAE libraries or you throw all your code in the project to get uploaded.

Second, GAE installs all the available libraries locally so you can develop with them. So you shouldn't go getting your own (potential version/addon conflict issues).

I've set up a very simple project. I haven't bothered to install a local SQL server yet. I'm on windows (aaaargh) aargh. I'm at the stage where I want to python manage.py syncdb. In settings.py, DATABASE must contain the connection info/url stuff. As I understand this can be for a local db (i.e. your own for dev or the cloud after deploying) with a mysql bit or set up to connect to the cloud from your local copy with rdbms (whatever that is). So I've set 'ENGINE': 'google.appengine.ext.django.backends.rdbms' and now get this error:

  Error was: No module named google.appengine.ext.django.backends.rdbms.base

I've uninstalled my local copy of django and set my PYTHONPATH=C:\Program Files (x86)\Google\google_appengine\lib\django-1.5. Without this set, I get an error so I have to assume it's using GAE's django. I've found a C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\django\backends\rdbms path too, which sounds relevant. So I'm not sure what to do next. I assume this rdbms thing is necessary to communicate with the SQL db remotely. I would like to be able to test locally/not in production.

What could be broken in my configuration to cause this?

As a side note, when ever I attempt to start a server with the GAE launcher, I just get ImportError: Could not import settings 'myblog.settings' (Is it on sys.path?): No module named appengine_toolkit. python manage.py runserver works fine until a request triggers an attempt to connect to a SQL server.

Upvotes: 2

Views: 514

Answers (1)

jozxyqk
jozxyqk

Reputation: 17364

The main thing I was missing here is making sure python could see the GAE libs. I solved this in linux:

export PYTHONPATH=/usr/local/google_appengine/:/usr/local/google_appengine/lib/:/usr/local/google_appengine/lib/django-1.5/

that's

  • google_appengine/
  • google_appengine/lib/
  • google_appengine/lib/django-1.5/

PYTHONPATH just didn't work on windows. Regarding Could not import settings 'myblog.settings', this only happens on windows and I couldn't figure out why and really can't be bothered wasting my time.

Two things that really helped me with GAE were:

  1. Having some idea of the intended (however implicitly) GAE project structure.
  2. Getting to grips with virtualenv (I found this was a decent intro), and promptly realizing how messy google app engine's launcher is regarding sandboxing and external libraries you want to use.

Eventually, my setup was as follows. I used virtualenv to install all my packages to the local env directory. To test locally, this worked fine (with the PYTHONPATH above). To deploy only the right packages (e.g. push django-wiki but not MySQLdb) I created a libs directory and simlinked everything I wanted in env/lib/python2.7/site-packages/.

As a better alternative to PYTHONPATH, something like this works (in settings.py):

IS_PRODUCTION = os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine')

if IS_PRODUCTION:
    sys.path.insert(0, 'libs')
else:
    sys.path.insert(0, 'env/lib/python2.7/site-packages/')

I also added a skip_files: section to app.yaml to exclude #- ^env/.* and uncomment this out when deploying. This probably wouldn't be necessary if I put my env outside the project directory like some others have mentioned.

Upvotes: 1

Related Questions