A summary of the extended discussion in the comment section and a more general question to 'why is my Python script not running when called from PHP, cgi, etc.?'
Can you call a Hello World script instead of your real script? e.g.
#!/usr/bin/env python or python3 from sys import version print(version)
If yes, great, then the problem is in your real Python script and not not the way you call it. Check if you can run the script from the command line (no simple indentation errors, truncated lines from copy&paste), preferably as the user who will execute the script when started via the server (i.e. not as root/admin). Use a logger to see where the script crashes.
In this particular case, wrap the whole starting Pytyhon and script, in a shell file and call this file from your server. A bit hacky but better than losing all your hair about it.
create a file file
echo "just a test to see if the script is executed, remove this line later" python3 /absolute/path/to/script/python_script.py
make sure the file is executable by using
chmod +x python_script.sh and then call this script via CGI or PHP.