Forums

ModuleNotFoundError: No module named 'mysite'

I know this question has been asked a million times, but i could not find a solution that would work for me, so i am sorry in advance. I am trying to start server using Django, but it seems that wsgi file cannot find the 'web' module, which i called my project. Here is the error log:

  File "/var/www/gigerin_pythonanywhere_com_wsgi.py", line 16, in <module>
    application = get_wsgi_application()
    File "/home/Gigerin/.virtualenvs/env/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
        django.setup(set_prefix=False)
      File "/home/Gigerin/.virtualenvs/env/lib/python3.9/site-packages/django/__init__.py", line 19, in setup
        configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
      File "/home/Gigerin/.virtualenvs/env/lib/python3.9/site-packages/django/conf/__init__.py", line 87, in __getattr__
        self._setup(name)
      File "/home/Gigerin/.virtualenvs/env/lib/python3.9/site-packages/django/conf/__init__.py", line 74, in _setup
        self._wrapped = Settings(settings_module)
      File "/home/Gigerin/.virtualenvs/env/lib/python3.9/site-packages/django/conf/__init__.py", line 183, in __init__
        mod = importlib.import_module(self.SETTINGS_MODULE)
      File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
    ModuleNotFoundError: No module named 'web'

Whenever I try to run python -i gigerin_pythonanywhere_com_wsgi.py to see if everything works correctly, the error above shows, but python shell starts. print(path) returns home/Gigerin/TeleBot/web, as it should. Here is the wsgi file:

import os
import sys

# assuming your Django settings file is at '/home/myusername/mysite/mysite/settings.py'
path = 'home/Gigerin/TeleBot/web'
if path not in sys.path:
    sys.path.insert(0, path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'web.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I cannot find anything wrong here, as the full path to settings.py is home/Gigerin/TeleBot/web/web/settings.py Again, i feel like there is something very obvious missing, i am sorry for bothering you with such trivialities.

It's probably the missing slash at the beginning of the path you're prepending, it should be /home/Gigerin/TeleBot/web instead.

Ugh, i knew it was something so stupid. Thank you very much!