Possible to run Python3 in Passenger?

I’m trying to run a web app written in Python 3 with Flask. I managed to set up everything else, the only issue seems to be that (as near as I can tell) Passenger is still calling the system based Python 2.7 and not my installed Python 3.6 which is called by the Virtual Environment and passenger_wsgi.py file.

Here is the error I am receiving (a Web application could not be started error)

Traceback (most recent call last):
File “/dh/passenger/helper-scripts/wsgi-loader.py”, line 320, in
app_module = load_app()
File “/dh/passenger/helper-scripts/wsgi-loader.py”, line 61, in load_app
return imp.load_source(‘passenger_wsgi’, startup_file)
File “passenger_wsgi.py”, line 4, in
os.execl(INTERP, INTERP, *sys.argv)
File “/usr/lib/python2.7/os.py”, line 312, in execl
execv(file, args)
OSError: [Errno 2] No such file or directory

My passenger_wsgi file:

import sys, os
INTERP = os.path.join(os.environ[‘HOME’], ‘mydomain.com’, ‘lenv’, ‘python3’)
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)

from myappname.app import app as application

Is there something I have formatted wrong or something I can do to understand and fix this issue? There shouldn’t be anything /usr/lib/python2.7/os.py and isn’t anywhere in my code, very confused.


passenger_wsgi.py is first executed by the system Python interpreter, which uses libraries from /usr/lib/python2.7. So that’s why that path is mentioned in the exception. I don’t see any bugs in your code, so the question is why your Python 3 executable isn’t being found.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.