How to Make mod_wsgi Use Python 3.9

Apache2mod-wsgipython

I originally had Python 3.6 installed and working well with WSGI and Apache2 on my Linux server.

Then I created a Flask app that had a dependency needing Python 3.7.
I've successfully (and I think) upgraded to Python 3.9.
Running

python3 or sudo python3

both take me to Python 3.9. But then when I run

sudo apt-get install libapache2-mod-wsgi-py3
The following additional packages will be installed: python3, python3.6

it installs Python 3.6

After this, python3 still points to Python 3.9. However, when the WSGI app is run, Python 3.6 is used, and it breaks. I have installed the Python package mod-wsgi with the correct PIP.

Best Answer

You should be able to control which pytho is used via a simple configuration line. E.g. /etc/httpd/conf.d/your_app.conf with

WSGIPythonHome /opt/your_python_env

(I would advise to also set up an venv dedicated to your app if you aren't already doing so)