ModuleNotFoundError: No module named 'settings' for any django project

Question:

I have been studying Django for some time and have been working on a project. Everything was fine until yesterday when I was studying a new topic, saved the project and shut down my PC. There were no errors or anything. Today, when I tried to run my project using the command "py manage.py runserver", I received an error "ModuleNotFoundError: No module named ‘settings’". I spent enough time trying to solve this problem and assumed that the error was in my project. I couldn’t solve it and decided to create a completely new project in a new virtual environment. To my surprise, the same error occurred in this completely new project as well. I thought that I might be doing something wrong, so I repeated the project creation on my laptop, and everything worked as expected with no errors. I tried reinstalling PyCharm and Python, but it didn’t help. I don’t think I can continue using Django on this PC anymore…

I don’t know what data may be needed to solve this problem, so I will provide at least something.
These are the data from the project that was just created.
Project structure
Installed modules
Full error:
During handling of the above exception, another exception occurred:

> Traceback (most recent call last):
> File "C:Django2metanitmanage.py", line 22, in <module>
> main()
> File "C:Django2metanitmanage.py", line 18, in main
> execute_from_command_line(sys.argv)
> File "C:Django2venvLibsite-packagesdjangocoremanagement__init__.py", line 446, in execute_from_command_line
> utility.execute()
> File "C:Django2venvLibsite-packagesdjangocoremanagement__init__.py", line 440, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
> File "C:Django2venvLibsite-packagesdjangocoremanagementbase.py", line 415, in run_from_argv
> connections.close_all()
> File "C:Django2venvLibsite-packagesdjangoutilsconnection.py", line 84, in close_all
> for conn in self.all(initialized_only=True):
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "C:Django2venvLibsite-packagesdjangoutilsconnection.py", line 76, in all
> return [
>            ^
> File "C:Django2venvLibsite-packagesdjangoutilsconnection.py", line 73, in __iter__
> return iter(self.settings)
>                 ^^^^^^^^^^^^^
> File "C:Django2venvLibsite-packagesdjangoutilsfunctional.py", line 57, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>                                          ^^^^^^^^^^^^^^^^^^^
> File "C:Django2venvLibsite-packagesdjangoutilsconnection.py", line 45, in settings
> self._settings = self.configure_settings(self._settings)
>                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "C:Django2venvLibsite-packagesdjangodbutils.py", line 148, in configure_settings
> databases = super().configure_settings(databases)
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "C:Django2venvLibsite-packagesdjangoutilsconnection.py", line 50, in configure_settings
> settings = getattr(django_settings, self.settings_name)
>                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "C:Django2venvLibsite-packagesdjangoconf__init__.py", line 92, in __getattr__
> self._setup(name)
> File "C:Django2venvLibsite-packagesdjangoconf__init__.py", line 79, in _setup
> self._wrapped = Settings(settings_module)
>                     ^^^^^^^^^^^^^^^^^^^^^^^^^
> File "C:Django2venvLibsite-packagesdjangoconf__init__.py", line 190, in __init__
> mod = importlib.import_module(self.SETTINGS_MODULE)
>           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "C:UserssuyarAppDataLocalProgramsPythonPython311Libimportlib__init__.py", line 126, in import_module
> return _bootstrap._gcd_import(name[level:], package, level)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
> File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
> File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
> File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
> File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
> File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
> File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
> ModuleNotFoundError: No module named 'settings'

I thought the error would disappear in the new project, but it remained. I repeated the same steps on my laptop, and everything worked there. Now I think my PC is "broken".

Asked By: Valentin Suyarov

||

Answers:

check that the directory containing the settings module is correctly configured in your project’s manage.py file. The manage.py file is the entry point for the Django project and must be correctly configured to launch the project properly.

Answered By: Idk

First, check if the version of python and django is consistent.

Maybe,it is possible that django is installed in a different location than the python guide package

Answered By: orange river

thanks everyone for the help, @Idk’s idea – to run manage.py directly led to the message – Note that only Django core commands are listed as settings are not properly configured (error: No module named 'settings') after which I found the solution for the first link to google, namely here, terminal command – set DJANGO_SETTINGS_MODULE=mysite.settings solved my problem

Answered By: Valentin Suyarov
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.