1. Home
  2. Python
  3. Using multiple versions with Passenger

Using multiple versions with Passenger

Overview

Passenger provides an intelligent polyglot launcher interface for managing Node.js, Ruby, and Python processes. This can be teamed up with pyenv to effortlessly launch multiple Python applications with a single shell command and .htaccess directive.

These steps are only necessary to use supplementary Python versions available on the server. If the default version works satisfactorily, then no further changes are necessary.

Usage

Applying what has been learned from KB article: “Changing python versions“, create a directory structure compatible with Passenger:

cd /var/www
mkdir -p mypyapp/{public,tmp}
cd mypyapp

Now assign it a Python interpreter. We’ll use 3.3.5:

pyenv local 3.3.5

Lastly, inform Passenger to use the pyenv-compatible python shim by adding PassengerPython /.socket/python/shims/python to a .htaccess file in public/

echo "PassengerPython /.socket/python/shims/python" > /var/www/mypyapp/public/.htaccess

Important: using pyenv’s shim system is considerably slower than accessing python directly, because a series of shell subprocesses are launched to resolve the python process necessary to satisfy a request. If using pyenv with Passenger, consider adapting it to the FastCGI specification for background persistence.

See also

Updated on July 8, 2019

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help! If you get an error, visit https://lithiumhosting.com/support instead.
Contact Support