Apache Enable Apache shebang python path
I am trying to update all my Python scripts to use the canonical shebang line for compatibility with Linux:
#!/usr/bin/env python
The problem is it doesn't work in Apache. The old shebang line works in Apache, which is
#!/usr/local/bin/python
The scripts run normally in Terminal, finding the Python executable specified by /usr/bin/env. But in Apache, the error I get is:
[cgid:error]~ End of script output before headers:
Why would Apache not find Python? Is there a diagnostic for this? I searched for hours looking for an explanation but found none. I am running OSX 10.13.3, Apache/2.4.29 and Python 3.6.4. Thank you for the help.
MacBook Pro with Retina display, macOS High Sierra (10.13.2), Thunderbolt display, iPhone 6S