Saturday, August 4, 2018

Python can import it, but django-admin can’t

For the Installing Lino page I tried to run a demo project (lino_book.projects.min1) using django-admin, i.e. without needing a file:

$ go min1
$ python -c "import settings.demo"

Works perfectly. But then:

$ django-admin runserver --settings settings.demo
Traceback (most recent call last):
  File "/py27/bin/django-admin", line 11, in <module>
  File "/py27/local/lib/python2.7/site-packages/django/core/management/", line 364, in execute_from_command_line
  File "/py27/local/lib/python2.7/site-packages/django/core/management/", line 308, in execute
  File "/py27/local/lib/python2.7/site-packages/django/conf/", line 56, in __getattr__
  File "/py27/local/lib/python2.7/site-packages/django/conf/", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/py27/local/lib/python2.7/site-packages/django/conf/", line 110, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/", line 37, in import_module
ImportError: No module named settings.demo


Here is the same problem using newest Django and without Lino.

In an empty directory I create a very minimal with the following content:

DEBUG = True

I install and activate a fresh environment with a Django:

$ virtualenv -p3 env
$ . env/bin/activate
$ pip install django

Now I am surprised that the following fails:

$ django-admin check --settings settings
Traceback (most recent call last):
ImportError: No module named 'settings'

This is strange because Python can import my without problem:

$ python -m settings
$ python -c "import settings"