We can see the python3 system version Ubuntu comes with and where its executable is stored using these commands.
python3 --version
which python3
Install required system packages, using superuser login with sudo
.
Enter y
to let the system package installation process do its job.
sudo apt-get install virtualenv python-pip python3-dev
Create a new virtualenv. This example uses the apps root folder.
cd /var/www/APP_NAME
# specify the system python3 installation
virtualenv --python=/usr/bin/python3 venv
Activate the virtualenv.
source /var/www/APP_NAME/venv/bin/activate
Our prompt will change after we properly activate the virtualenv. Our virtualenv is now activated with Python 3. We can install dependencies. For example, from a requirements.txt file located in APP’s code file:
cd /var/www/APP_NAME/code
sudo pip install -r requirements.txt
Create a common folder to store virtual environments. For example, in user’s home directory.
cd ~
mkdir venvs
Create a new virtualenv, specifying version.
# specify the system python3 installation
virtualenv --python=/usr/bin/python3 venvs/APP_NAME
Activate the virtualenv.
source /venvs/APP_NAME/bin/activate
Our prompt will change after we properly activate the virtualenv. Our virtualenv is now activated with Python 3. We can install dependencies. For example, from a requirements.txt file located in APP’s code file:
cd /var/www/APP_NAME/code
sudo pip install -r requirements.txt
Edit passenger config file to point to APP’s virtualenv. Example from phusionpassenger.com
http {
passenger_root ...;
# Use Ruby 2.1 by default.
passenger_ruby /usr/bin/ruby2.1;
# Use Python 2.6 by default.
passenger_python /usr/bin/python2.6;
# Use /usr/bin/node by default.
passenger_nodejs /usr/bin/node;
server {
# This Rails web app will use Ruby 2.2.1, as installed by RVM
passenger_ruby /usr/local/rvm/wrappers/ruby-2.2.1/ruby;
listen 80;
server_name www.bar.com;
root /webapps/bar/public;
# If you have a web app deployed in a sub-URI, customize
# passenger_ruby/passenger_python inside a `location` block.
# The web app under www.bar.com/blog will use JRuby 1.7.1
location ~ ^/blog(/.*|$) {
alias /websites/blog/public$1;
passenger_base_uri /blog;
passenger_app_root /websites/blog;
passenger_document_root /websites/blog/public;
passenger_enabled on;
passenger_ruby /usr/local/rvm/wrappers/jruby-1.7.1/ruby;
}
}
server {
# This Flask web app will use Python 3.0
passenger_python /usr/bin/python3.0;
listen 80;
server_name www.baz.com;
root /webapps/baz/public;
}
}
These step-by-step instructions are taken from various tutorials on digitalocean.com, phusionpassenger.com, and other sites. Some sources have been linked. Most step descriptions have been shortened and simplified. Some step sequences are from one source while other may come from various sources.
These instructions and commands are placed on GitHub so I can conveniently find them. I am a novice with Ubuntu, Nginx, Passenger, command line, etc., so I probably can’t answer any questions. However, I’ll be glad to incorporate any corrections that are needed.
Use instructions and commands at your own risk.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.