Preparing for the classes


The (revised) plan is to do this as a full-day workshop although I would have preferred to break it up into shorter segments. Content will be mostly me droning on about the stuff in these notes with participants doing some live Python/Django coding on their laptops. Some of the material here may be too basic or the opposite so it’s hard to estimate how much time it will take. We may refer to some stuff and then skip ahead. Anything not done in class should be done as homework. We can always add on more sessions if we need to. For CUIT staff, you can always ask questions on Slack channel #python-dev


  • It is expected that students will bring laptops that have a functional Python development environment set up, including Python 3.5 or higher, git, an editor or IDE, maybe Docker for some of the advanced examples. The examples are all MacOS-based, using the Unix CLI. Windows users will need to adjust as needed.

  • Optionally have PyCharm installed and licensed (not required; PyCharm CE works fine too). Or use an editor like Emacs, vi or atom. However, PyCharm’s ability to interactively debug is a lot more powerful than $ python -m pdb ....

  • git

    • CLI tools installed

    • access to gitlab/github

    • have successfully created one’s own personal repo.

  • Some familiarity with: JSON, HTTP, REST, XML, SOAP/WSDL, SQL, git, pycharm, Python object-oriented programming, Django, etc. I don’t really care if you’ve heard of XML, SOAP or WSDL other than if you have heard of them, but not JSON or REST, they’ll be a point of comparison. Similarly, knowledge of SQL can be cursory, basically understanding the concepts of tables and fields (columns).

Development Environment Setup

Most all steps on macOS will be performed using the Unix shell. Open the “Terminal” application for this.


Only macOS is supported by Homebrew. Windows users can skip this section.


Homebrew is a package management system used to simplify software installations on macOS.

Run the command listed at



Once Homebrew is installed, it should be simple install python:

brew install python

More details are available at:

You can create an alias in your ~/.bashrc or ~/.bash_profile file to set python3 as default:


alias python='python3'

See more about running “multiple versions of Python for use with tox on macOS”, below, for more advanced Python tricks.



This should install Python3 in C:\\Program Files\\Python36



The Git installation for macOS is easily done with Homebrew:

brew install git

If you would prefer to install this manually without homebrew, see:


  1. Download git from

  2. Click ‘Run as administrator’ on the .exe file in your Downloads directory.

  3. Set the installation directory to the following path: C:\\Program Files\\Git

  4. If there is an option to add git to your path, select it.

  5. Accept all defaults otherwise.

If git was not added to your path, add the above directory to your system’s Environment Variables


PyCharm is an IDE for Python development. This instruction applies to both macOS and Windows.

Download the professional or community edition from the following link and follow the setup instructions:


Postman is a powerful tool for testing HTTP. We’ll be using it extensively to test our APIs. If you don’t already have it, you can get it at:

Multiple Version of Python for use with Tox on macOS

Why do I need multiple Python versions?

The problem: typical tox.ini files test against multiple version of Python – py34, py35, py36 – so you need all those versions installed on macOS. For the purposes of this material, you can get by with the system version as described above.

Installing pyenv

Install pyenv:

brew install pyenv

Add eval "$(pyenv init -)" to your bash profile (or similar for other shells):

cat >>~/.bash_profile
eval "$(pyenv init -)"

Don’t forget to do the eval once if you have an open shell window.

Installing multiple Python versions with pyenv

Then choose versions of python you want. pyvenv install -l lists what’s available. There are many flavors and versions. We just care about 3.[456] right now:

pyenv install -l | grep '^  3\.[456]'

Install those versions and make them “global”

pyenv install 3.4.8
pyenv install 3.5.5
pyenv install 3.6.6
pyenv global 3.6.6 3.5.5 3.4.8

Installation under Mojave and XCode 10

See this issue where pyenv install complains about missing zlib. Here’s a workaround:

CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" \
PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 \
pyenv install -v 3.7.0

Choosing which Python version to use

The preceding will make python3.6, python3.5 and python3.4 globally available. The first-listed version is the one that becomes “python”:

python --version
Python 3.6.6

pyenv global makes the versions global (for you only; it updates ~/.pyenv/version)

pyenv local makes the versions local to the CWD (it updates .python-version). Local settings override global.

See for more.

Install the tox-pyenv plugin

This plugin makes tox magically find the versions required in the tox.ini file.

pip3.6 install tox tox-pyenv

For example, in a tox.ini that tests a matrix of multiple Python versions, it will make sure py34 uses python3.4, py35 uses python3.5 and so on.

Here’s a snippet from a Django add-on library that does a cross-product series of tests of three Python versions against django 2.0 and the django project’s current master branch:

envlist =
commands = pytest --cov=oauth2_provider --cov-report= --cov-append {posargs}
setenv =
        DJANGO_SETTINGS_MODULE = tests.settings
        PYTHONPATH = {toxinidir}
        PYTHONWARNINGS = all
deps =
        django20: Django>=2.0,<2.1

If you’re running tox and you have all the interpreters installed already you can use tox -e to choose the one version to run tox with. Otherwise, tox will run with py34, py35 and then py36.

tox -e py36

Installing system python

You can still use homebrew to install the system python. Brew-installed system python is located in /usr/local/bin. macOS (High Sierra or older) also still installs py27 in /usr/bin.

$ brew install python
Updating Homebrew...
Python has been installed as

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into

If you need Homebrew's Python 2.7 run
  brew install python@2

Pip, setuptools, and wheel have been installed. To update them run
  pip3 install --upgrade pip setuptools wheel

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory


You can also install a newer version of legacy Python 2.7:

brew install python@2

This might be a bit confusing since the pyenv shim is still first in your path (thanks to eval "$(pyenv init -)"):

$ python --version
Python 3.6.6
$ which python
$ which python3.7
$ which python
$ /usr/local/bin/python --version
Python 2.7.15
$ /usr/local/bin/python3 --version
Python 3.7.0
$ /usr/bin/python --version
Python 2.7.10