tags:

views:

138

answers:

3

Hi all:

It's weird to me that the import fails even when it's in the sys.path.

today, I set up a google app engine django environment on ubuntu in my lab's pc. And it works fine when I checked out the code and ran it in windows(same pc in the lab).

But when I went to the dorm, and checked out the code and start to run, it failed weirdly.

I print the sys.path, like this:

['/home/tower/googlecode/mygae', '/home/tower/googlecode/mygae/.google_appengine', '/home/tower/googlecode/mygae/.google_appengine/lib/antlr3', ...]

and when I ran python complained

from google.appengine.api import apiproxy_stub_map
ImportError: No module named appengine.api

it's easy to know the google module is in the '/home/tower/googlecode/mygae/.google_appengine' directory, and the __init__.py for each module is present.

So what can be the reason for this weird thing? Or what I messed up probably?

thanks.

+1  A: 

Sometimes you can get an import error for a module when the error is something different, like a syntax error. Try putting

import pdb;pdb.set_trace()

just before the import and then s(tep) into the import, and n(ext) thruogh the module in question to see of you get an error.

Lennart Regebro
+1  A: 

Can you import google and google.appengine? Are you sure interpreter has read and traverse access rights to the module tree?

wRAR
I've tried. import google is ok. but import google.appengine fails.I guess maybe google is already in the system's global path, since I try to import google in other places, it succeeds. maybe they collide. I'm trying to figure out.
Tower Joo
print google.__path__
wRAR
they truly collided. the google__path__ shows it's in the /var/lib/python-support/python2.6. I'm wondering the import should traverse from the sys.path one by one in order, and if it imports successfully it should stop. But seems import doesn't traverse in the list's order. I should read some docs to know more.Really thanks. it works.
Tower Joo
A: 

Looks like you're getting a module (or package) called 'google' from elsewhere -- perhaps /home/tower/googlecode/mygae -- and THAT google module has no appengine in it. To check, print google.__file__ and if possible google.__path__; that should be informative.

Alex Martelli