N
N
Nikita Juzz2022-04-12 21:15:23
Django
Nikita Juzz, 2022-04-12 21:15:23

Why does a Django module error occur when trying to start the server?

Installed virtual environment, installed django, while writing command

django-admin --version


the correct version is shown. It also shows that pip has everything you need installed.

(demoEnv) PS E:\frontendprog\slave-projeckt\with_tutor\with_tutor> django-admin --version
    4.0.4
    
        (demoEnv) PS E:\frontendprog\slave-projeckt\with_tutor\with_tutor> pip list
        Package         Version
        --------------- -------
        asgiref         3.5.0
        dj-database-url 0.5.0
        Django          4.0.4
        gunicorn        20.1.0
        Pillow          9.1.0
        pip             22.0.4
        psycopg2        2.9.3
        setuptools      61.0.0
        sorl-thumbnail  12.8.0
        sqlparse        0.4.2
        tzdata          2022.1
        wheel           0.37.1
        whitenoise      6.0.0

When I try to start the local server, I get

(demoEnv) PS E:\frontendprog\slave-projeckt\with_tutor\with_tutor> python manage.py runserver
    Traceback (most recent call last):
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv       
        self.execute(*args, **cmd_options)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\core\management\commands\runserver.py", line 74, in execute
        super().execute(*args, **options)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\core\management\base.py", line 460, in execute
        output = self.handle(*args, **options)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\core\management\commands\runserver.py", line 81, in handle 
        if not settings.DEBUG and not settings.ALLOWED_HOSTS:
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\conf\__init__.py", line 87, in __getattr__
        self._setup(name)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\conf\__init__.py", line 74, in _setup
        self._wrapped = Settings(settings_module)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\conf\__init__.py", line 183, in __init__
        mod = importlib.import_module(self.SETTINGS_MODULE)
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "E:\frontendprog\slave-projeckt\with_tutor\with_tutor\with_tutor\settings.py", line 141, in <module>
        import dj_database_url
    ModuleNotFoundError: No module named 'dj_database_url'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "E:\frontendprog\slave-projeckt\with_tutor\with_tutor\manage.py", line 21, in <module>
        main()
      File "E:\frontendprog\slave-projeckt\with_tutor\with_tutor\manage.py", line 17, in main
        execute_from_command_line(sys.argv)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line   
        utility.execute()
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\core\management\__init__.py", line 440, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\core\management\base.py", line 427, in run_from_argv
        connections.close_all()
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\db\utils.py", line 212, in close_all
        for alias in self:
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\utils\connection.py", line 73, in __iter__
        return iter(self.settings)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\utils\functional.py", line 49, in __get__
        res = instance.__dict__[self.name] = self.func(instance)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\utils\connection.py", line 45, in settings
        self._settings = self.configure_settings(self._settings)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\db\utils.py", line 148, in configure_settings
        databases = super().configure_settings(databases)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\utils\connection.py", line 50, in configure_settings
        settings = getattr(django_settings, self.settings_name)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\conf\__init__.py", line 87, in __getattr__
        self._setup(name)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\conf\__init__.py", line 74, in _setup
        self._wrapped = Settings(settings_module)
      File "E:\frontendprog\slave-projeckt\with_tutor\demoEnv\lib\site-packages\django\conf\__init__.py", line 183, in __init__
        mod = importlib.import_module(self.SETTINGS_MODULE)
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "E:\frontendprog\slave-projeckt\with_tutor\with_tutor\with_tutor\settings.py", line 141, in <module>
        import dj_database_url
    ModuleNotFoundError: No module named 'dj_database_url'


Then I found a similar problem and downloaded, as everyone advises on

> pip install
And more
> pip3 install

Everything should be downloaded and working.
And when I write:

(demoEnv) PS E:\frontendprog\slave-projeckt\with_tutor\with_tutor> python3 manage.py runserver
    Traceback (most recent call last):
      File "E:\frontendprog\slave-projeckt\with_tutor\with_tutor\manage.py", line 10, in main
        from django.core.management import execute_from_command_line
    ModuleNotFoundError: No module named 'django'
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "E:\frontendprog\slave-projeckt\with_tutor\with_tutor\manage.py", line 21, in <module>
        main()
      File "E:\frontendprog\slave-projeckt\with_tutor\with_tutor\manage.py", line 12, in main
        raise ImportError(
    ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?


It's a completely different error. Although I have everything downloaded.

(demoEnv) PS E:\frontendprog\slave-projeckt\with_tutor\with_tutor> pip3 list   
    Package         Version
    --------------- -------
    asgiref         3.5.0
    dj-database-url 0.5.0
    Django          4.0.4
    gunicorn        20.1.0
    Pillow          9.1.0
    pip             22.0.4
    psycopg2        2.9.3
    setuptools      61.0.0
    sorl-thumbnail  12.8.0
    sqlparse        0.4.2
    tzdata          2022.1
    wheel           0.37.1
    whitenoise      6.0.0

I found an answer on the Internet, only that everything needs to be installed on pip3, but I have everything installed on both pip and pip3, and when using python and python3, different errors come out, although everything is downloaded and responds. I no longer know what to do.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question