I'm working with Django 1.4 and Python 2.7.
I've encountered this issue before, but was able to work around it by adding the parent directory to sys.path using this code:
import sys
def rtrim(s, sep):
return sep.join(s.split(sep)[0:-1])
sys.path.insert(0, rtrim(sys.path[0], '/'))
from django.core.management import setup_environ
import settings
setup_environ(settings)
Today, seemingly out of nowhere, it reared its ugly head once more. The directory structure is as follows:
Ingest/
settings.py
ingest/ (current working directory)
test.py
Here are sys.path and part of the Traceback:
['/mnt/c/Users/Travis/Documents/GitHub/{redacted}/Ingest', '/mnt/c/Users/Travis/Documents/GitHub/{redacted}/Ingest/ingest', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'Ingest.settings' (Is it on sys.path?): No module named settings
As you can see, the parent directory is in sys.path.