Ubuntu released the newest Long Term Support (LTS) version of its operating system in April 2016. The update brings Ubuntu to version 16.04 and its latest code name is "Xenial Xerus". 16.04 is the first Ubuntu release to include Python 3 as the default Python installation.
We will need a few tools to complete our project. Don't worry about installing these just yet as we'll get to them as we progress through the tutorial. The tools and their current versions as of May 9, 2016 are:
If you are running Mac OS X or Windows, use virtualization software such as Parallels (this is what I use, but it's Mac OS X-only) or VirtualBox with the Ubuntu .iso file. Either the amd64 or i386 version of 16.04 is fine, but I use amd64 for development and testing in this blog post.
When we boot up for the first time, we should see a desktop screen like this one.
Open up terminal to proceed with the setup.
We can see the python3 version Ubuntu comes with, as well as where its executable is stored.
python3 --version which python3
Our Ubuntu installation first needs system packages for Python development. You'll be prompted for your superuser password because restricted system access is required to install packages through apt.
sudo apt-get install virtualenv python-pip python3-dev
y and let the system package installation process run.
The basic system packages we need are now installed so we can proceed to our Python-specific dependencies.
Virtualenv and pip for isolating and handling application dependencies were just installed via system packages so we can now use them to obtain Django and Gunicorn.
Create a directory to store virtualenvs then put a new virtualenv in it.
# the tilde "~" specifies the user's home directory, like /home/matt cd ~ mkdir venvs # specify the system python3 installation virtualenv --python=/usr/bin/python3 venvs/djproject
Activate the virtualenv.
We should see our prompt change so that we know the virtualenv is properly activated.
Our virtualenv with Python 3 is activated so we can install whatever dependencies we want, such as Django and Gunicorn.
Time to install Django and Green Unicorn into our virtualenv.
pip install django gunicorn
No errors is a good sign everything worked for us.
Create a new Django project named
djproject, or whatever you want to name
your project. Then change into the directory for the new project.
django-admin startproject djproject cd djproject
We could run Django with the development server using the
python manage.py runserver command. However, start Django up with
Awesome, now we can bring up our shell project in the web browser at
Ready for development!
Those are the basics for starting development with Django and Gunicorn on Ubuntu 16.04. If you need an even more in-depth step-by-step tutorial to deploy your Python web application to a production environment, check out the Full Stack Python Guide to Deployments book.
To figure out what to do next for your Python project, read the topics found on the table of contents page.
See something wrong in this post? Fork this page's source on GitHub and submit a pull request.