'Syntax Error when deploying django on apache2

I am trying to host a django application on a server using apache2 and mod_wsgi.

The project itself is located at the path /usr/share/django-projects/mysite

The virtual environment is located at the path /home/zakhar/django_test/env

It's part of apache2 (2.4 version) conf file. In venv python version is 3.8.13

WSGIDaemonProcess mysite user=www-data group=www-data python-path=/usr/share/django-projects/mysite:/home/zakhar/django_test/env/lib/python3.8/site-packages python-home=/home/zakhar/django_test/env

It's last error from apache arror.log

File "/home/zakhar/django_test/env/lib/python3.8/site-packages/django/db/models/aggregates.py", in line 84
if (default := c.default) is None:
            ^
SyntaxError: invalid syntax

I think apache use python 3.6.9 in global env, but not in venv

I would be very grateful if someone could help me



Solution 1:[1]

I installed mod_wsgi in my venv and edited /etc/apache2/mods-avaible/wsgi.load

LoadModule wsgi_module "/home/zakhar/django_test/env/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so"
WSGIPythonHome "/home/zakhar/django_test/env"

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Zakhar