Python 3 Installation

Python is one viable solution for writing custom code for this course. If you’d like to try this or experiment with the Python video-processing examples, this guide should help you set up a system on your own computer.

Python is free and open-source, but some examples will require additional open-source packages beyond the stock Python system. The recommended solution is to use the standard distribution from the Python Software Foundation along with a few additional packages.

macOS Installation Notes

To install the standard Python system, please perform the following:

  1. Download the current Python package from the Python Downloads page. For Spring 2021, we will be using the macOS Python 3.8.7 version. Please do not install 3.9.x, not all packages are available for it yet.

  2. Open the .pkg file you downloaded to start the installer.

  3. Allow a default install to proceed; it will require a user password for authorization to install into system folders.

  4. Run the Install Certificates.command after installation as recommended by the prompts.

This process will install a working base Python system in /Applications and /Library/Frameworks, with symbolic links in /usr/local/bin.

The additional third-party packages are best installed from the command line (e.g. Terminal.app). Please open a Terminal window and execute the following commands:

pip3 install opencv-contrib-python

The OpenCV installation should also install NumPy as a dependency. There are other possible sources for OpenCV packages, but this is the specific package used for course software development.

Other packages not needed now but which have proven to be useful:

pip3 install PyQt5
pip3 install scipy
pip3 install scikit-learn
pip3 install matplotlib
pip3 install python-rtmidi
pip3 install python-osc
pip3 install pyserial

If this is successful, please proceed below to Testing the Installation.

Windows Installation Notes

For a detailed explanation, please see the Python Windows guide in the official Python documentation.

There are many choices available during installation and many possible installation situations, so my instructions may not work exactly the same for you. But the critical objectives are as follows:

  1. The Python installation is included in the system PATH variable. This enables running Python programs from the command line.

  2. The py launcher is installed. The launcher enables running Python programs by double-clicking on .py files.

  3. pip is installed. pip is a convenient tool for installing third-party Python packages, which we’ll need to do after the base install.

With that in mind, the following sequence may help you through installation:

  1. Download the current Python package from either Python Downloads or Python Windows Downloads. The default installer type is the “x86-64 executable installer”. For Spring 2021, I am testing using Windows Python 3.8.7. Please do not install 3.9.x, not all packages are available for it yet.

  2. Run the .exe file you downloaded to start the installer.

  3. Please enable the checkbox labeled “Add Python..to PATH”.

  4. Select Install Now to proceed. You’ll need to confirm Yes in the User Account Control (UAC) dialog which appears.

  5. After installation on Windows 10, you may be offered the option to Disable path length limit. This generally appears to be a good idea unless you are still developing software for Windows 8 or earlier. You’ll need to confirm Yes to another UAC dialog.

The default install places the base Python system in your AppData folder, e.g. C:\Users\garthz\AppData\Local\Programs\Python\Python38. Some alternate options may place it elsewhere.

We will need several additional packages to run the course software. These third-party packages are most easily installed from the command line, available on Windows as Command Prompt from the Windows System section of the Start Menu, or by typing cmd from the Start Menu Run option. Please open the command line window and type the following:

pip3 install opencv-contrib-python

The OpenCV installation should also install NumPy as a dependency. There are other possible sources for OpenCV packages, but this is the specific package used for course software development.

Other packages not needed now but which have proven to be useful:

pip3 install PyQt5
pip3 install scipy
pip3 install scikit-learn
pip3 install matplotlib
pip3 install python-rtmidi
pip3 install python-osc
pip3 install pyserial

If pip3 is not found, then it is likely Python was not added to the system PATH environment variable. Some possible fixes for this:

  1. Modify settings by using the Windows Settings panel. Locate Python on the Apps section, select it, then click Modify. Under Optional Features please ensure that pip and the py launcher are enabled. Under Advanced Features you might try enabling ‘Associate files with Python’ and ‘Add Python to environment variables’.

  2. Restart the system.

  3. Re-run the Python installation from scratch.

If you are eventually successful, please proceed below to Testing the Installation.

Testing the Installation

To test the new installation, please try running the interpreter from the command line:

$ python3

On some installations, it may instead be named python (without the digit). Please check the banner message to verify you’ve run the right version.

You may then attempt to import a few packages at the interpreter prompt by typing the following:

import numpy
import cv2
exit()

The result should look generally similar to this transcript:

$ python3
Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import cv2
>>> exit()

Python Tutorials and References

Some starting points for Python programming:

Third-party packages:

Documentation on some particular packages we may use:

  • OpenCV: computer vision and image processing

  • NumPy: numeric and matrix computations

  • PyQt5: GUI and application programming using the Qt5 system

  • SciPy: scientific algorithms

  • scikit-learn: machine learning

  • Matplotlib: data plotting and visualization

Editing Python

Python is a whitespace-sensitive language in which indentation must be precise. This essentially requires use of a syntax-sensitive programming text editor. We recommend using the Mu Python editor.

Other options include the IDLE editor included with the Python installation. The XCode editor works with Python. Advanced command-line users may enjoy emacs or vim. Many people seem to like the commercial Sublime Text application.

A much longer list can be found at https://wiki.python.org/moin/PythonEditors

Alternative Installations

There are other options for obtaining Python, including the ones listed below. However, only the python.org distribution will be directly supported by the course.

  1. macOS, Windows, Linux: Anaconda Python

  2. macOS: MacPorts Python 3

  3. Ubuntu or Debian Linux: native package system