Spurious ImportErrors (with modules importing submodules?) Spurious ImportErrors (with modules importing submodules?) django django

Spurious ImportErrors (with modules importing submodules?)


Actually your strace line does not help a bit; those accesses did not result in the module being imported.

There might be multiple reasons for such import errors:

  1. someone modifies sys.path and that is not within the module path anymore
  2. a cyclical import in those modules, that is triggered by you importing from another module first!
  3. you have site conflict (yep, had that kind of), same module being loaded from different site packages locations
  4. you have a module in the search path conflicting with an other module somewhere, or with a system module.

If you would paste the SECOND set of strace lines, we would be closer to solution?

Update

For 2. I mean that if you have 2 files with the following structure

foo.py/init.py:

from bar import baz

bar.py/init.py:

import foodef baz():     pass

snafu.py:

import barimport foo

ok.py:

import fooimport snafu

Run python snafu.py and you get a crash and similar strace output, run python ok.py and everything works.


The strace output seems suspicious to me:

DIR/django/contrib/gis/...

I am wondering about this DIR part. Is it possible you misstyped the PYTHONPATH variable somewhere, using DIRinstead of $DIR?


I'd suggest you to wrap the import with a try... except ImportError and add a code doing something like that (anything that logs, instead of print, will do)

import sysprint sys.modules["django.contrib.gis.maps.google"]print dir(sys.modules["django.contrib.gis.maps.google"])

This should let you understand what's happening.