Django 1.5b1: executing django-admin.py causes "No module named settings" error
Asked Answered
D

5

20

I've recently installed Django-1.5b1. My system configuration:

  • OSX 10.8
  • Python 2.7.1
  • Virtualenv 1.7.2

When I call django-admin.py command I get the following error

(devel)ninja Django-1.5b1: django-admin.py 
Usage: django-admin.py subcommand [options] [args]

Options:
  -v VERBOSITY, --verbosity=VERBOSITY
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings=SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath=PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Print traceback on exception
  --version             show program's version number and exit
  -h, --help            show this help message and exit
Traceback (most recent call last):
  File "/Users/sultan/.virtualenvs/devel/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/core/management/__init__.py", line 452, in execute_from_command_line
    utility.execute()
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/core/management/__init__.py", line 375, in execute
    sys.stdout.write(self.main_help_text() + '\n')
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/core/management/__init__.py", line 241, in main_help_text
    for name, app in six.iteritems(get_commands()):
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/core/management/__init__.py", line 108, in get_commands
    apps = settings.INSTALLED_APPS
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/conf/__init__.py", line 52, in __getattr__
    self._setup(name)
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/sultan/.virtualenvs/devel/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'settings' (Is it on sys.path?): No module named settings

Did anyone have the same errors? Can anyone advise or help with it?

Thanks,

Sultan

Drury answered 8/12, 2012 at 8:22 Comment(1)
I tried to install Django 1.4.2 and Django 1.3.4 and everything works just fineDrury
O
37

I had the same issue when starting a new project. I solved the problem by giving this command at the command prompt:

export DJANGO_SETTINGS_MODULE=

in this way I unset the variable that was pointing to a "settings" file (discovered using env | grep DJANGO_SETTINGS_MODULE) I set before starting using virtualenv

after unsetting the variable the django-admin.py script worked like a charm!

Oblong answered 20/6, 2013 at 14:2 Comment(4)
It's not the best solution, you should include PYTHONPATH, like @ceolwulf answer suggested: https://mcmap.net/q/131097/-django-1-5b1-executing-django-admin-py-causes-quot-no-module-named-settings-quot-errorCyprus
Thanks @neosergio. Can you please elaborate why it should be the best solution? Sultan had an erroneous value in DJANGO_SETTINGS_MODULE and my suggestion was to remove that value in order to use virtualenv's one.Oblong
You can modify DJANGO_SETTINGS_MODULE with proper value (especially when you separate settings file e.g: local or production) and you'll continue have the problem if your PYTHONPATH it's not explicit identified, that's why @ceolwulf's answer fix the problem and also allow set DJANGO_SETTINGS_MODULE in env.Cyprus
@Cyprus I agree, but you may still have the problem if you fix PYTHONPATH and you have set a wrong DJANGO_SETTINGS_MODULE (as I and Sultan did at least once) so my answer and ceowulf's one complement each other. The downvote should be given if the suggestion is wrong, if you give it because it's incomplete, you should downvote also all the other ones...Oblong
D
16

I've had the same issue as you, and I haven't come up with a good fix aside from prepending my project folder to the PYTHONPATH like this:

export PYTHONPATH="/absolute/path/to/django/project/folder:$PYTHONPATH"

where my <project> is located at /absolute/path/to/django/project/folder/<project>. I add that export command to the end of my env/bin/activate script so it happens every time I initialize the virtualenv.

The only difference between our two situations is that I use multiple settings files instead of a single settings.py module.

You can also call django-admin.py from the folder containing your Django project like so:

python ~/.virtualenvs/devel/bin/django-admin.py <command>

so that it recognizes your current working directory as part of the path.

Hope that makes sense. It's kind of clumsy to explain which makes it hard to search for an answer.

Dramaturgy answered 21/2, 2013 at 6:3 Comment(0)
P
1

Maybe your problem is related to this: Wrong python path in script header

If you want to do anything except creating a new django project inside your venv, you should call python manage.py (of course, whereis python should return your venv executable)

Prettypretty answered 9/12, 2012 at 3:53 Comment(0)
B
0

Don't run the script from the direct path to the django library; run it from any other path. It seems you cd into the directory where django is installed (or where you downloaded and expanded it) and then ran the command from there.

So try this:

(devel)ninja Django-1.5b1: cd 
(devel)ninja: django-admin.py startproject foo
Brook answered 9/12, 2012 at 4:1 Comment(0)
G
-2

Are you sure you are starting the django-admin from the virtualenv django instalation ? Perhaps path/to/virtualenv/bin/django-admin.py

Gould answered 8/12, 2012 at 9:52 Comment(2)
Yes I am, the command which django-admin.py shows /Users/sultan/.virtualenvs/devel/bin/django-admin.pyDrury
yes sorry, just saw that. he other reason is that the django is not on the python path. I don't know witch python is starting the main system or the virtual env python. But something is wrong with the paths ....Gould

© 2022 - 2024 — McMap. All rights reserved.