Developing With Python 3.6 on Ubuntu 16.04 LTS - Getting Started and Keeping Control
Recently, I started developing locally on my Ubuntu machine again, without having all of my development environment dockerized.
Here’s the approach I use to work with Python3.6 on Ubuntu 16.04 LTS, and the setup steps which I used to set everything up. As those notes are in-retrospect, it might be the case that I missed a detail or two.
Install Python 3.6 Packages
So, first you’ll need to add a ppa, which contains Python3.6 packages. This is described in this StackOverflow thread:
The ppa part is not necessary, if you’re on Ubuntu 16.10, as the package is available there.
# make sure you have ppa prerequisites in place $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt-get update $ sudo apt-get install python3.6 $ sudo apt-get install python3-pip
As we’ll be developing and using pip, we’ll need at least one more package:
$ sudo apt-get install python3.6-dev
Virtualenv and Virtualenvwrapper
We’ll use virtualenv in any case, to create isolated Python environments, so our projects don’t mess with each other’s dependencies, nor the OS packages.
$ sudo pip3.6 install virtualenv
I still really like virtualenvwrapper to interact with different virtualenvs. Check out how to install it, and give it a try! It’s neat-o. Here’s what you can do once it’s configured:
$ mkvirtualenv -p python3.6 py3
That created a new virtualenv, using Python 3.6, and activates it right away. Now we KNOW, that we’re working with the right Python version, and there are less weird issues to run into.
Where to go from here
From now on, you can activate your new virtualenv, with the command:
$ workon py3
You can install tools which you need system-wide and across projects. We don’t need to specify the pip or python version once we’re working in the right virtualenv.
For me, one tool I needed was cookiecutter:
$ pip install cookiecutter
Once it’s installed, I can use it to create a new Django project, with the glorious cookicutter-django framework.
$ cookiecutter https://github.com/pydanny/cookiecutter-django
For the new project, we can create a new virtualenv, once again specifying the right Python version, install requirements and be sure that everything’s nice and tidy.
$ mkvirtualenv -p python3.6 new-django-project # the new environment is activated $ pip install -r requirements/local.txt
Join the mailing list!
Subscribe to get notified about future articles and stay in touch via email.
I write about Kubernetes, Docker, automation- and deployment topics, but would also like to keep you up to date about news around the business-side of things.