views:

259

answers:

4

I'm trying to teach myself python using Google's AppEngine, and I can't get the dev server running. I get this error:

Traceback (most recent call last):
File "/opt/google_appengine/google_appengine_1.2.7/dev_appserver.py", line 60, in run_file(file, globals()) File "/opt/google_appengine/google_appengine_1.2.7/dev_appserver.py", line 57, in run_file execfile(script_path, globals_) File "/opt/google_appengine/google_appengine_1.2.7/google/appengine/tools/dev_appserver_main.py", line 65, in from google.appengine.tools import os_compat ImportError: cannot import name os_compat

Ubuntu 9.10 comes with python2.6 (didn't work), and I installed python2.5 (didn't work), and have tried running it with python dev_appserver.py helloWorld (didn't work) as well as running dev_appserver.py after editing the first line to be:

#!/usr/bin/env python2.5

I can't seem to find anything online with this error. The only problem I've found is about using python 2.5, and I think I've solved that.

Kyle suggested I need to set my PYTHONPATH variable. After running

export PYTHONPATH=/opt/google_appengine/google_appengine_1.2.7

I still get the same error trying to run dev_appserver.py. Am I setting PYTHONPATH wrong? Alternatively, how do I uninstall the protocol buffers python project? I have no use for Ubuntu One and had already uninstalled it.

A: 

With that error, Python is saying that it can't find or read the name that it's trying to import. Since the import of os_compat is the very first executable line of AppEngine's dev_appserver.py, I suspect that there's a problem with the way that your paths are configured.

Joe Hughes
+3  A: 

The problem appears to be the fact that Karmic Koala 9.10 (the latest version of Ubuntu) ships with Ubuntu One, a python app that depends on Google's protocol buffers library. The python-protobuf package provides the google.protobuf package in /usr/lib/pymodules/python2.6.

Unfortunately, the AppEngine SDK includes another package called google.appengine. So somewhere in your code, the google package is being imported, and the package that contains protobuf is being found on PYTHONPATH first. Python caches the first package it finds in sys.modules, so the second google package in the SDK will never be imported.

You could move the google AppEngine SDK up to the front of your PYTHONPATH. That should ensure that Python finds the google.appengine package instead of the package provided by python-protobuf.

PYTHONPATH=/opt/google_appengine/google_appengine_1.2.7 \
    python dev_appserver.py helloWorld

This is a bug that should be reported to the AppEngine SDK project.

Update: I've submitted a bug against the AppEngine API.

Kyle Ambroff
I still get the same error message. Edited the question to say so.
Steve Armstrong
A: 

It was a file permission problem. os_compat.py wasn't readable by user, just by root. I'm not sure if I screwed this up, or if the permissions by default don't have read-all, but that was the fix.

I hate to accept my own answer after Kyle gave such a good response, but I don't need the $PYTHONPATH fix to make it work now that I did sudo chown -R +r /opt/google_appengine/google_appengine_1.2.7

Steve Armstrong
A: 

The latest version of Ubuntu (10.10) has also removed Python 2.5 - making it a pain to install the App Engine development environment.

I (finally) got my environment working (including using App Engine Helper for unit testing). I built this bash script which might be useful to others. It installs:

  1. sqlite
  2. libsqlite
  3. pep8
  4. mock
  5. OpenSSL
  6. Python 2.5.2
  7. Python SSL Library
  8. Django 1.1 (latest version in production)
  9. App Engine
  10. App Engine Helper

http://pageforest.googlecode.com/hg/tools/pfsetup

mckoss