Python 3 Installation¶
Particular exercises will use Python 3 programs running 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:
Download the current Python package from the Python Downloads page. For Fall 2020, we will be using the macOS Python 3.8.5 version.
Open the .pkg file you downloaded to start the installer.
Allow a default install to proceed; it will require a user password for authorization to install into system folders.
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 PyQt5
pip3 install paho-mqtt
pip3 install scipy
pip3 install scikit-learn
pip3 install matplotlib
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:
The Python installation is included in the system PATH variable. This enables running Python programs from the command line.
The py launcher is installed. The launcher enables running Python programs by double-clicking on .py files.
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:
Download the current Python package from either Python Downloads or Python Windows Downloads. The default installer type is the “x86-64 executable installer”. For Fall 2020, I am testing using Windows Python 3.8.6.
Run the .exe file you downloaded to start the installer.
Please enable the checkbox labeled “Add Python..to PATH”.
Select Install Now to proceed. You’ll need to confirm Yes in the User Account Control (UAC) dialog which appears.
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 PyQt5
pip3 install paho-mqtt
pip3 install scipy
pip3 install scikit-learn
pip3 install matplotlib
If pip3 is not found, then it is likely Python was not added to the system PATH environment variable. Some possible fixes for this:
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’.
Restart the system.
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 PyQt5
import paho.mqtt
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 PyQt5
>>> import paho.mqtt
>>> exit()
Python Tutorials and References¶
Some starting points for Python programming:
Tutorials: https://www.python.org/about/gettingstarted/
Language documentation: https://docs.python.org/3/
Third-party packages:
Documentation on some particular packages we may use:
paho-mqtt: real-time network communication using MQTT servers
NumPy: numeric and matrix computations
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.
For beginners, the IDLE
editor included with the Python installation is
recommended. 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