Django Deployment: ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named settings.py

StackOverflow https://stackoverflow.com/questions/7105691

Question

Hi All and thank you for taking the time to look at my question.

I'm a newbie to Python, thought I have experience in php/mysql.

I was just handed a code repository of a django site and asked to get it up and running on a server. I've been able to run syncdb and migrate. Now I'm trying to navigate to my site in the browser and this is the error that I get:

ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named settings.py

My apach2.conf python config looks like this:

<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonOption django.root /myproject
SetEnv DJANGO_SETTINGS_MODULE settings.py
PythonPath "['/home/ubuntu/envs/live/','/home/ubuntu/envs/live/myproject','/home/ubuntu/envs/live/myproject/apps', '/home/ubuntu/envs/stage/myproject', '/home/ubuntu/envs/', '/var/www'] + sys.path"
PythonDebug on

The settings.py file is in the directory /home/ubuntu/venvs/live/myproject.

Can someone please help me here?

Thanks!

Was it helpful?

Solution

It should be just:

SetEnv DJANGO_SETTINGS_MODULE settings

No '.py'. Ie., it is a Python module path, not a file name.

Do note that mod_python is officially a dead project. The support in Django has been deprecated. You should look at alternatives instead of mod_python for hosting Django.

OTHER TIPS

I think you should flip the order of the following lines:

SetEnv DJANGO_SETTINGS_MODULE settings.py
PythonPath "['/home/ubuntu/envs/live/','/home/ubuntu/envs/live/myproject','/home/ubuntu/envs/live/myproject/apps', '/home/ubuntu/envs/stage/myproject', '/home/ubuntu/envs/', '/var/www'] + sys.path"

First set the Python path where settings.py can be found, and then set the env to that file.

But, you should really just install on the mod-wsgi as very well documented.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top