skip to Main Content

I am trying to set up a simple Django==4.0.6 dev environment on my Ubuntu 20.04. I’m creating a project folder, create and activate a venv first. Then I’m installing Dajngo using pip. I’m then creating a new project in the very same directory and then for testing this out, run the usual python manage.py command. Here’s a quick list of commands I am using:

mkdir project && cd project
python3 -m venv venv
source venv/bin/activate
pip install django==4.0.6
django-admin startproject major .
python manage.py migrate

But I’m getting the following error:

Traceback (most recent call last):
  File "/project/venv/lib/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/project/venv/lib/python3.8/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/project/venv/lib/python3.8/site-packages/django/core/management/base.py", line 95, in wrapped
    saved_locale = translation.get_language()
  File "/project/venv/lib/python3.8/site-packages/django/utils/translation/__init__.py", line 210, in get_language
    return _trans.get_language()
  File "/project/venv/lib/python3.8/site-packages/django/utils/translation/__init__.py", line 65, in __getattr__
    if settings.USE_I18N:
  File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 87, in __getattr__
    self._setup(name)
  File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 74, in _setup
    self._wrapped = Settings(settings_module)
  File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 183, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app'

And further down, the rest of the error reads:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/project/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/project/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/project/venv/lib/python3.8/site-packages/django/core/management/base.py", line 427, in run_from_argv
    connections.close_all()
  File "/project/venv/lib/python3.8/site-packages/django/db/utils.py", line 212, in close_all
    for alias in self:
  File "/project/venv/lib/python3.8/site-packages/django/utils/connection.py", line 73, in __iter__
    return iter(self.settings)
  File "/project/venv/lib/python3.8/site-packages/django/utils/functional.py", line 49, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/project/venv/lib/python3.8/site-packages/django/utils/connection.py", line 45, in settings
    self._settings = self.configure_settings(self._settings)
  File "/project/venv/lib/python3.8/site-packages/django/db/utils.py", line 148, in configure_settings
    databases = super().configure_settings(databases)
  File "/project/venv/lib/python3.8/site-packages/django/utils/connection.py", line 50, in configure_settings
    settings = getattr(django_settings, self.settings_name)
  File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 87, in __getattr__
    self._setup(name)
  File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 74, in _setup
    self._wrapped = Settings(settings_module)
  File "/project/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 183, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app'

I wasn’t able to find a similar case where someone got the same error using a plain new installation in a virtual environment.

I haven’t modified any files in the installation, fresh installation only. I was wondering if this has to do anything with my non-env Python. But I couldn’t figure out what it is following the traceback.

Update:

  • I have tested this on every other machine and it works fine as it is a simple installation process for any Django project.

2

Answers


  1. if you created folder ‘app’ manually and there don’t exists _ _ init _ _.py – you receive those Error.

    Login or Signup to reply.
  2. Is your $DJANGO_SETTINGS_MODULE environment variable set to something with app in it by any chance?

    Related documentation: https://docs.djangoproject.com/en/4.0/topics/settings/#designating-the-settings

    To fix, unset that environment variable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search