mod_wsgi icon indicating copy to clipboard operation
mod_wsgi copied to clipboard

Error: (Internal server error) Django apache2 - mod_wsgi

Open PachaDev2 opened this issue 2 years ago • 9 comments

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 ??

PachaDev2 avatar Jan 02 '23 10:01 PachaDev2

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.

GrahamDumpleton avatar Jan 02 '23 10:01 GrahamDumpleton

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>

PachaDev2 avatar Jan 02 '23 10:01 PachaDev2

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.

GrahamDumpleton avatar Jan 02 '23 10:01 GrahamDumpleton

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.

GrahamDumpleton avatar Jan 02 '23 19:01 GrahamDumpleton

I added the sys.path it works wonderfully Thanks very much

PachaDev2 avatar Jan 03 '23 09:01 PachaDev2

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. :-(

GrahamDumpleton avatar Jan 03 '23 10:01 GrahamDumpleton

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]

`

PachaDev2 avatar Jan 04 '23 12:01 PachaDev2

And if you run Python 3.10 from the command line and from the interpreter print sys.path, what do you get?

GrahamDumpleton avatar Jan 04 '23 20:01 GrahamDumpleton

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']

PachaDev2 avatar Jan 07 '23 15:01 PachaDev2