Django "Could not import settings 'settings.py'" error
Remove the .py
file extension and add the project context to your settings module definition. Assuming that your project is called acecoach
.
SetEnv DJANGO_SETTINGS_MODULE acecoach.settings
The Python documentation explains the reason simpler than I shall attempt to.
http://docs.python.org/tutorial/modules.html#modules
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
http://docs.python.org/tutorial/modules.html#packages
Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.B designates a submodule named B in a package named A.
Related videos on Youtube
![Ernie](https://i.stack.imgur.com/JdhRB.jpg?s=256&g=1)
Ernie
Updated on September 17, 2022Comments
-
Ernie almost 2 years
I've already done my best to follow the instructions at http://docs.djangoproject.com/en/dev/howto/deployment/modpython/, but a customer is transferring a website to us, and I suspect the original developer's methods were a bit, uh, different.
So, first the full error message:
ImportError: Could not import settings 'settings.py' (Is it on sys.path? Does it have syntax errors?): No module named py
Then, the apache configuration for the site:
<Location /acecoach/> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE settings.py PythonOption django.root /acecoach PythonPath "['/home/acecoach/public_html/acecoach'] + sys.path" PythonDebug On </Location>
Now, the "settings module" as far as I know, is located in
/home/acecoach/public_html/acecoach/settings.py
This file is readable by the apache server - I tested this by actually SU-ing to the apache user and reading the file from the command line.I've also read similar advice on this error message, and found no useful help in this regard. It's driving me nuts. :)
-
Graham Dumpleton over 14 yearsBecause they only have directory '/home/acecoach/public_html/acecoach' in PythonPath, they would actually use 'settings' and not 'acecoach.settings'. Rather than do that though, they should add '/home/acecoach/public_html' to PythonPath as well and keep using 'acecoach.settings'.
-
Graham Dumpleton over 14 yearsYours was a different issue. This person was using Python file extension when they shouldn't have.