Import error when module is already in sys.path

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

.

today, I have installed django environment for google app on ubuntu in my lab pc. And it works great when I checked the code and ran it in windows (same computer in the lab).

But when I went to the dorm and checked the code and started working, it was weird.

I am typing sys.path

for example:

['/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 is easy to find out that the google module is in the '/home/tower/googlecode/mygae/.google_appengine'

directory and __init__.py

for each module.

And what could be causing this strange thing? Or perhaps what I messed up?

thank.

0


source to share


4 answers


Can you import google

and google.appengine

? Are you sure the interpreter has read and traversal permissions to the module tree?



+2


source


I had the same problem on Ubuntu when I wanted to play with google.appengine in the console. I first tried to fix this by removing the package /usr/lib/python2.7/dist-packages/google

altogether, but Ubuntu One . Finally I solved it by bundling the google GAE SDK into the package that caused the collision .

The contents of the directory /usr/lib/python2.7/dist-packages/google

now look like this:



/google
    /appengine
    /net
    /protobuf
    /pyglib
    /storage
    /__init__.py
    /__init__.pyc

      

+2


source


It looks like you are getting a module (or package) called "google" from somewhere else - perhaps /home/tower/googlecode/mygae

- and this module does not have google appengine

. To check, print google.__file__

and, if possible google.__path__

,; it should be informative.

+1


source


Sometimes you might get an import error for a module when the error is something else, such as a syntax error. Try to put

import pdb;pdb.set_trace()

      

just before import, then s (tep) in import and n (ext) through that module to see that you got the error.

0


source







All Articles