Error: (Internal server error) Django apache2 - mod_wsgi
Hello, I'm trying to deploy my web application designed with django, after testing the web server where I hosted my django project, I got the error: Internal server Error By consulting the errors.log file I have: (no module named 'django') I looked on the env folder (virtual environment) where django is installed, I see that the django package is on env/dist-packages and not on env/lib/python3.10/site-packages ??
Make sure you read:
- https://modwsgi.readthedocs.io/en/master/user-guides/virtual-environments.html
You should not be referencing dist-packages or site-packages when telling mod_wsgi where the Python virtual environment is. You should be telling it where the root of the virtual environment is. There are various incorrect blog posts out there about this.
Without seeing the mod_wsgi configuration you are using, that is all the advice I can give you.
000-default.conf
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIDaemonProcess project python-home=/home/ubuntu/project/env python-path=/home/ubuntu/project
WSGIProcessGroup project
WSGIScriptAlias / /home/ubuntu/project/app/wsgi.py
<Directory /home/ubuntu/project/app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
Your mod_wsgi module may not actually be compiled for Python 3.10, but a different version. Do the checks in:
- https://modwsgi.readthedocs.io/en/master/user-guides/checking-your-installation.html#python-installation-in-use
to work out what the version of Python is, verify what installation it is using, and what sys.path is being set to.
Fixed for Python 3.10 even before 3.10 was released.
- https://modwsgi.readthedocs.io/en/master/release-notes/version-4.9.0.html#bugs-fixed
If you are still having issues and want help you need to supply the information I asked for above. That is, run the checks I linked to and supply the exact output from the scripts for sys.version, sys.prefix and sys.path. I can't guess what is happening without such further details.
Also confirm whether you are using system package for Python, whether you have installed your own Python from source code or are using Anaconda Python.
I added the sys.path it works wonderfully Thanks very much
I didn't ask you to modify sys.path if that is what you did to get it to work. I was asking for the values of those variables so I could understand how your system is setup and try and working out whether Ubuntu Python has broken embedding, or whether you are mixing up different Python versions. :-(
Here are the outputs of its variables: `
print(sys.prefix) /usr print(sys.path) ['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages'] print(sys.version) 3.10.7 (main, Nov 24 2022, 19:45:47) [GCC 12.2.0]
`
And if you run Python 3.10 from the command line and from the interpreter print sys.path, what do you get?
print(sys.path)
['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/usr/local/lib/python3.10/dist-packages', '/usr/lib/python3/dist-packages']