Home > database >  ModuleNotFoundError: No module named 'tutorial'
ModuleNotFoundError: No module named 'tutorial'

Time:01-18

I am trying to learn how to set up a Django web server using an AWS Ubuntu Machine, I have solved a few of my problems but now I am getting hit with the ModuleNotFoundError: No module named 'tutorial' and I am also getting the 500 internal server error.

Here is what I think the necessary code is:

error.log

  GNU nano 6.2                                                        /home/ubuntu/django-project/site/logs/error.log                                                                  
[Mon Jan 16 19:35:18.750368 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] mod_wsgi (pid=10330): Failed to exec Python script file '/home/ubuntu/djang>
[Mon Jan 16 19:35:18.750441 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] mod_wsgi (pid=10330): Exception occurred processing WSGI script '/home/ubun>
[Mon Jan 16 19:35:18.750979 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] Traceback (most recent call last):
[Mon Jan 16 19:35:18.751031 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "/home/ubuntu/django-project/src/tutorial/wsgi.py", line 16, in <mod>
[Mon Jan 16 19:35:18.751037 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]     application = get_wsgi_application()
[Mon Jan 16 19:35:18.751043 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751048 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]     django.setup(set_prefix=False)
[Mon Jan 16 19:35:18.751053 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751058 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Jan 16 19:35:18.751068 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751073 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]     self._setup(name)
[Mon Jan 16 19:35:18.751078 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751083 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]     self._wrapped = Settings(settings_module)
[Mon Jan 16 19:35:18.751088 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751092 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Jan 16 19:35:18.751097 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_mod>
[Mon Jan 16 19:35:18.751102 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]     return _bootstrap._gcd_import(name[level:], package, level)
[Mon Jan 16 19:35:18.751107 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[Mon Jan 16 19:35:18.751112 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[Mon Jan 16 19:35:18.751117 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
[Mon Jan 16 19:35:18.751122 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_remo>
[Mon Jan 16 19:35:18.751128 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[Mon Jan 16 19:35:18.751133 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[Mon Jan 16 19:35:18.751146 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330]   File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlock>
[Mon Jan 16 19:35:18.751161 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] ModuleNotFoundError: No module named 'tutorial'

wsgi.py

"""
WSGI config for tutorial project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings')

application = get_wsgi_application()

default000.conf

<VirtualHost *:80>

        ErrorLog /home/ubuntu/django-project/site/logs/error.log
        CustomLog /home/ubuntu/django-project/site/logs/access.log combine

        <Directory /django-project/src/tutorial>

                Require all granted

        </Directory>


        WSGIDaemonProcess tutorial python-home=/home/ubuntu/django-project/venv python-path=/home/ubuntu/django-project/src/tutorial/
        WSGIProcessGroup tutorial
        WSGIScriptAlias / /home/ubuntu/django-project/src/tutorial/wsgi.py

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


MY folder layout
── site
│   ├── logs
│   │   ├── access.log
│   │   └── error.log
│   └── public
│       ├── media
│       └── static
├── src
│   ├── db.sqlite3
│   ├── manage.py
│   └── tutorial
│       ├── __init__.py
│       ├── __pycache__
│       │   ├── __init__.cpython-310.pyc
│       │   ├── settings.cpython-310.pyc
│       │   ├── urls.cpython-310.pyc
│       │   └── wsgi.cpython-310.pyc
│       ├── asgi.py
│       ├── settings.py
│       ├── urls.py
│       └── wsgi.py
└── venv
    ├── bin
    │   ├── __pycache__


I was following an instruction guide and I was running into errors left and right, I just want my mysql and django to link on my page.

CodePudding user response:

according to your files your project name is "tutorial" and the error is caused by

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings')

in wsgi.py (but this is correct - the root cause is in your non standard folder structure). How does your folder structure look like?

Should be according to django standard:

src/
   tutorial/
      tutorial/
         settings.py
         urls.py
         wsgi.py

From your Apache config I can see that wsgi.py is not in the correct folder.

Should be:

WSGIScriptAlias / /home/ubuntu/django-project/src/tutorial/tutorial/wsgi.py

  • Related