Score:5

How to make mod_wsgi use Python 3.9?

ru flag

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.

Score:1
cn flag

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)

Saleh avatar
no flag
But the mod_wsgi doc said the version of python you are pointing via the above setting, should match the version which mod_wsgi is compiled against. So that should not work for chaning the python major/minor version. Am I right?
Ricky Levi avatar
jp flag
I'm also receiving `Invalid command 'WSGIPythonHome'` when I check for `apachectl -S`
Ricky Levi avatar
jp flag
@Saleh then in that case, how the command line gives python3.9 but Apache is using python3.8 - how can it be upgraded then (for Apache) because this affects the `pip install` pkgs, for testing i'm installing with `3.9` but for Apache I need to install it again for `3.8` ?! ... something doesn't make any sense. ( the 3.9 was installed with homebrew, while the system-wide python is in `/usr/bin`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.