Python 3 Installation¶
The Webots simulator requires a Python 3 installation in order to run the sample controllers. We will also be using Python 3 extensively for developing performance software. For this reason, you will need an up-to-date installation 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 2023, we will be using the macOS Python 3.11.4 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 python-osc
pip3 install pyserial
pip3 install scipy
pip3 install opencv-python
These packages are also recommended as project resources:
pip3 install PyQt6
pip3 install python-rtmidi
pip3 install mido
pip3 install matplotlib
pip3 install scikit-learn
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 2023, I am testing using Windows Python 3.11.4.
Run the .exe file you downloaded to start the installer.
Please enable the checkbox labeled “Add Python to environment variables.” (In older versions this was “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\Python39
. 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:
pip install python-osc
pip install pyserial
pip install scipy
pip3 install opencv-python
These packages are also recommended as project resources:
pip install PyQt6
pip install python-rtmidi
pip install mido
pip install matplotlib
pip install scikit-learn
If pip
is not found, you may try pip3
. If neither is 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. Depending on your system, the command may be either python
or python3
:
python
python3
Please check the banner message to verify you’ve run the right version, especially if you’ve previously installed Python, since multiple versions can co-exist on your system.
You may then attempt to import a few packages at the interpreter prompt by typing the following:
import numpy
import PyQt6
import pythonosc
exit()
The result should look generally similar to this transcript:
$ python3
Python 3.11.4 (v3.11.4:d2340ef257, Jun 6 2023, 19:15:51) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import PyQt6
>>> import pythonosc
>>> 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:
python-osc: real-time networked message communication using the Open Sound Control (OSC) standard
NumPy: numeric and matrix computations
SciPy: scientific algorithms
scikit-learn: machine learning
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
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.