Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not import settings. Import by name is not supported

I have a Python 2.7/Django 1.4 project. I'm running Ubuntu 11. The project structure has a root folder of Notecard, a project named Notecard, and an app named Notecards:

notecard/

-- notecard/

-- -- manage.py

-- -- settings.py

-- -- __init__.py

-- -- urls.py

-- -- notecards/

-- -- app2/

I'm running Linux, and the path to the root folder is `/home/dan/notecard/

My PYTHONPATH variable is:

>>> os.environ['PYTHONPATH'].split(os.pathsep)
['', '/home/dan/notecard', '/home/dan', '/home/dan/notecard/notecard/settings']

My DJANGO_SETTINGS_MODULE is:

>>> os.environ['DJANGO_SETTINGS_MODULE'].split(os.pathsep)
['notecard.settings', '/home/dan/notecard/settings', '/home/dan/notecard/notecard/settings']

And my Manage.py is:

#!/usr/bin/env python
import os, sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "notecard.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

I use PyCharm as my IDE, and when I try to run the dev server I get the following:

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

My settings are all correct in the Django Support section of Pycharm.

When I try to run the dev server directly from the terminal I get:

ImportError: Could not import settings 'notecard.settings:/home/dan/notecard/settings:/home/dan/notecard/notecard/settings' (Is it on sys.path?): Import by filename is not supported.

From the terminal, it seems to be picking up multiple environmental variables. I'm not sure why - I thought it should take one that matches.

I'm having a tough time figuring out how to get this working - preferably through Pycharm, but hopefully in general.

I've obviously tried adding all of the environmental variables, verifying the Pycharm settings and verifying my manage.py system variable info as well (just in case.)

Any help would be appreciated.

like image 947
Dan Hoerst Avatar asked Jan 31 '26 11:01

Dan Hoerst


1 Answers

The trouble, as the error message says, is your DJANGO_SETTINGS_MODULE. Why do you have multiple values for that? It needs to just be a single value: a module path. In your case it should probably be notecard.settings.

like image 196
Daniel Roseman Avatar answered Feb 02 '26 03:02

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!