How do I get Apache to use the default pyenv Python version instead of the system one?

I am using plain Apache 2.4 on Mac OS Catalina.

I installed pyenv to manage python versions. The default Python is 3.8.0

Now I try to have Python scripts running in Apache. I created a subdomain under localhost that makes sure python code will run. But it seems to use the system python version(s) and not the one from pyenv.

When I use shebang:

#!/usr/bin/python

Then python 2 is used. Not what I want...

When I use:

#!/usr/bin/python3

It uses the system python3 version (3.7.3) Which is the python at /usr/bin/python3

How do I get Apache to use the "default" python that I see when I execute: "pyenv global"?


If the python version you want to use is:

/opt/local/bin/python

just replace the 1st line of the scripts you want to run with this version of python to say you want to use this interpreter:

#!/opt/local/bin/python