'PythonAnywhere "ModuleNotFound Error django"

Im working on hosting a Django app on pythonanywhere. I had it semi working before changing a few things that a guide suggested, before it started running a ModuleNotFoundError saying Django was not installed, even though I did install it in the virtual environment.

This is the error code:

2022-03-23 21:16:01,911: Error running WSGI application
2022-03-23 21:16:01,913: ModuleNotFoundError: No module named 'django'
2022-03-23 21:16:01,913: File "/var/www/coleabell05_pythonanywhere_com_wsgi.py", line 88, in <module>
2022-03-23 21:16:01,913: from django.core.wsgi import get_wsgi_application

The changes I made before this started happening are: I remade my Github repo by incorporating a .gitignore file before pushing to the repo as suggested by the guide (I forgot to make this file the first time I made the repo and cloned into PythonAnywhere). The file consists of this:

# Python
*.pyc
*~
__pycache__

# Env
.env
myvenv/
venv/

# Static folder at project root
/static/

# macOS
._*
.DS_Store
.fseventsd
.Spotlight-V100

# pycharm
.idea/

I pushed my project to Github, and then at the repo on github I manually inserted this into the .gitignore file before cloning to PythonAnywhere:

wintergardendjango/settings.py

I then cloned this repo via the console on pythonanywhere and made a new virtual environment where I again installed django. I updated all my paths to reflect the new virtual environment ect. The error being called is in the WSGI file which is:

# To use your own django app use code like this:
import os
import sys

#
## assuming your django settings file is at '/home/coleabell05/mysite/mysite/settings.py'
## and your manage.py is is at '/home/coleabell05/mysite/manage.py'
path = '/home/coleabell05/wintergardendjango'
if path not in sys.path:
    sys.path.append(path)
#
os.environ['DJANGO_SETTINGS_MODULE'] = 'wintergardendjango.settings'
#
## then:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I've tried remaking the virtual environment and redownloading django but it continues to throw the error. Any ideas for what could be the cause?

Edit: I ended up redoing the repo without the .gitignore and it all worked. Curious what in that file could have caused the error?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source