How can I tell Phusion Passenger which python to use?

帅比萌擦擦* 提交于 2020-01-02 05:15:14

问题


I'm using Phusion Passenger with a ruby app and I'd also like to set it up to work with an django appengine app I'm working on.

Googling for "passenger_wsgi.py" I was able to get the following very simple non-django app working on passenger:

passenger_wsgi.py:

def application(environ, start_response):
   response_headers = [('Content-type','text/plain')]
   start_response('200 OK', response_headers)
   return ['Hello World!\n']

However, if I add the line import django.core.handlers.wsgi into the mix, I get 'An error occurred importing your passenger_wsgi.py'. By printing out the sys.path I've discovered that at least part of the reason is because Passenger is using the wrong python installation on my machine.

How can I configure Passenger (on apache) to use /opt/local/bin/python2.5 instead of the system default python?


回答1:


I discovered that if I changed the hashbang at the first line of passenger's request_handler.py file to #!/opt/local/bin/python2.5, passenger used the correct python. But surely there must be a better way than modifying passenger's distribution?




回答2:


One trick is to include a line like this in your passenger_wsgi.py file:

if sys.version < "2.4":  
     os.execl("/usr/bin/python2.4", "python2.4", *sys.argv)

or

INTERP = "/usr/local/bin/python"  
    if sys.executable != INTERP:  
        os.execl(INTERP, INTERP, *sys.argv)

Each of these basically tells the environment to use your preferred python.




回答3:


You can specify the python interpreter via the PassengerPython variable in the server config, virtual host, directory, or .htaccess file.

apache: PassengerPython

nginx: passenger_python

standalone: --python



来源:https://stackoverflow.com/questions/2842336/how-can-i-tell-phusion-passenger-which-python-to-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!