apache wsgi_mod fails to run on python 3.10

Viewed 1760

I am developing a django app using django 4 and python 3.10. I had a server using apache and mod_wsgi, that used to run an old app using python3.8.

I've created a virtual env from 3.10. Command line manage.py is working well.

I've changed apache's conf:

WSGIDaemonProcess my_app310 python-path=/home/ubuntu/my_app310:/home/ubuntu/venv/my_app310/lib/python3.10/site-packages
WSGIProcessGroup my_app310
WSGIScriptAlias / /home/ubuntu/my_app310/my_app310/wsgi.py

But I keep getting:

[mpm_event:notice] AH00489: Apache/2.4.41 (Ubuntu) mod_wsgi/4.6.8 Python/3.8 configured -- resuming normal operations
[core:notice] AH00094: Command line: '/usr/sbin/apache2'
[wsgi:error] mod_wsgi (pid=1724834): Failed to exec Python script file '/home/ubuntu/my_app310/my_app310/wsgi.py'.
[wsgi:error] mod_wsgi (pid=1724834): Exception occurred processing WSGI script '/home/ubuntu/my_app310/my_app310/wsgi.py'.
[wsgi:error]  Traceback (most recent call last):
[wsgi:error]     File "/home/ubuntu/venv/my_app310/lib/python3.10/site-packages/django/utils/timezone.py", line 10, in <module>
[wsgi:error]       import zoneinfo
[wsgi:error] ModuleNotFoundError: No module named 'zoneinfo'

Which suggest that something is running using python3.8 and not python3.10 (mod_wsgi?). What am I missing?

2 Answers

to configure apache2 with a certain Python Version just do the following:

  1. go into your virtual_env that you have created with Python3.10
  2. $ pip install mod_wsgi
  3. $ mod_wsgi-express module-config

you get an output like

LoadModule wsgi_module "..../lib/python3.10/site-packages/mod_wsgi/server/mod_wsgi-py310.cpython-310-x86_64-linux-gnu.so"
SSGIPythonHome "..."
  1. copy the 2 lines into /etc/apache2/apache2.conf
  2. restart apache2 you should see something like
[mpm_event:notice] AH00489: Apache/2.4.41 (Ubuntu) mod_wsgi/4.6.8 Python/3.10 config .....

WSGI Clearly says that File "/home/ubuntu/venv/my_app310/lib/python3.10/site-packages/django/utils/timezone.py", given this path has no module named zoneinfo try importing module into your python virtual environment. Example: pip install (module)

Related