Sam
Sam

Reputation: 2084

DJANGO_SETTINGS_MODULE not recognizing my base module when starting a new project with Virtualenvwrapper

I am starting a new Django project with virtualenvwrapper, and for some reason django-admin does not recognize my settings module:

$ mkproject djangotest
(djangotest) $ pip install Django

Collecting Django
  Using cached Django-2.0-py3-none-any.whl
Collecting pytz (from Django)
  Using cached pytz-2017.3-py2.py3-none-any.whl
Installing collected packages: pytz, Django
Successfully installed Django-2.0 pytz-2017.3

(djangotest) $ django-admin

The above command works and gives me the menu of django-admin subcommands. However, when I try to set DJANGO_SETTINGS_MODULE, my new djangotest app is not recognized:

(djangotest) $ cd ../
(djangotest) $ django-admin startproject djangotest
(djangotest) $ cd djangotest
(djangotest) $ ls
djangotest     manage.py

(djangotest) $ export DJANGO_SETTINGS_MODULE=djangotest.settings
(djangotest) $ django-admin

Traceback (most recent call last):
  File "/Users/sam/Dropbox/.virtualenvs/djangotest/bin/django-admin", line 11, in <module>
    sys.exit(execute_from_command_line())
  File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/core/management/__init__.py", line 317, in execute
    settings.INSTALLED_APPS
  File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/sam/Dropbox/.virtualenvs/djangotest/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'djangotest'

Any idea why the 'djangotest' module is not being found?

Upvotes: 1

Views: 275

Answers (1)

thomasw_lrd
thomasw_lrd

Reputation: 546

I had this same issue. It turns out I need to be inside the app when I ran the manage.py command.

Upvotes: 1

Related Questions