Local Django development with Docker and Python 3.5
I was chatting with a friend of mine the other day about new Shopify apps to build with Django. We decided it's finally time to start using Python 3.
Python 3 was actually released almost 8 years ago (and the programming language itself is over 25 years old!). But adoption had been slow due to backwards incompatibility with previous versions. There are tons of third-party Python libraries and if your project uses one of these libraries and it turns out that library is no longer maintained or the maintainer has no plan to port it to Python 3, then you could get stuck from upgrading as well if it's critical to your project.
For new projects, however, it makes sense to consider moving to Python 3 now as maintenance for Python 2 is currently set to end in 2020. There are of course many improvements as well such as new modules, type hinting (Python 3.5), and treating all strings as unicode by default.
In our case, all the packages we plan to use already have Python 3 ports, so it was an easy decision to switch.
For local development, since I use Docker, I had to update my docker-django-local project (a set of Dockerfiles for local Django development) to include Python 3.5 support. The images will work with Python 2.7 and Python 3.5, but with Python 3.5 the commands will be slightly different.
For example, to install Python 3 versions of packages via pip, we'll need to specify the specific version of the Python interpreter to use:
docker-compose run django python3.5 -m pip install -r requirements.txt
And to run Django management commands:
docker-compose run django python3.5 manage.py migrate
Other than those, the rest of the process is pretty much the same.
Here's the GitHub link to the Docker Django Local project: https://github.com/jcalazan/docker-django-local
Tags: docker, python, django, tech, software development