Using Python in IDeATe¶
The example code for the course includes Python scripts, primarily for controlling hardware via a serial-attached Arduino. The following notes will guide you in getting started on running the examples on the IDeATe cluster laptops.
Contents
Python in the IDeATe MBP Cluster¶
The course primarily supports using the IDeATe cluster MacBook Pro laptops for Python development. However, these laptops have at least three different Python intepreters:
- MacPorts Python (recommended):
/opt/local/bin/python2.7
- The system Python supplied by Apple:
/usr/bin/python
- An independent Python 3:
/usr/local/bin/python3
The standard Python libraries are quite comprehensive but do not include several essential libraries needed for Physical Computing work (notably pySerial). For this reason, the only supported interpreter is the MacPorts installation.
An example of running a course Python script from the command line (e.g. Terminal) might look like this:
$ /opt/local/bin/python2.7 mini_maestro_dfmoco.py --help
The initial $
represents the prompt, /opt/local/bin/python2.7
the
specific Python interpreter from MacPorts, mini_maestro_dfmoco.py
is the
particular script to run, followed by command-line arguments. In this case,
--help
will simply print out all possible arguments.
Python in the IDeATe Dell Cluster¶
The course materials have not yet been tested under Windows 10 on the IDeATe Dell cluster laptops. However, these machines have Anaconda Python 2 and 3 installed so in principle should work.
Reference: IDeATe Software.
Python Tutorials¶
For tutorials: https://www.python.org/about/gettingstarted/
For documentation: https://www.python.org/doc/
For information on third-party packages: https://pypi.python.org/pypi
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 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
Python 2.7 vs 3.5¶
Python currently exists in two major branches. Python 3 introduced incompatible features, so many projects have continued to use Python 2 for better library support. The situation is slowly resolving as libraries are being ported forward.
The course materials are written in a 2/3 compatible style and tested on both Python 2.7 and 3.5. Currently, 2.7 is recommended for use on the IDeATe laptops but the transition to 3 is underway. Please note that 3.5 isn’t the latest version, but we expect newer versions to work equally well.
For more details on cross-version compatibility, please see Python-Future.
Python on your own laptop¶
Since we provide the cluster machines, we will not provide support for your personal systems, it is just too labor-intensive. But if you’d like to set one up, here are notes which may help.
macOS MacPorts¶
MacPorts is an open-source package installation system for macOS. Effective use of MacPorts requires some willingness to use the command line (e.g. Terminal.app). The MacPorts Quickstart instructions are the best reference for initial installation.
The following command line will then install all additional packages required by the course examples. Note that you may see many other packages installed by MacPorts as it automatically installs packages required by the ones you specify:
sudo port install python27 py27-future py27-serial py27-numpy py27-pyqt5 qt5-mac
If you’d prefer to use Python 3, you could also try this:
sudo port install python35 py35-future py35-serial py35-numpy py35-pyqt5
Additional recommended packages:
sudo port install py27-pip py27-virtualenv py35-pip py35-virtualenv
macOS or Windows Anaconda Python¶
Anaconda is a Python distribution for Windows, Mac or Linux which includes a package manager and comprehensive package system. The installer will include many third-party packages in the default installation, notably PyQt5 and numpy. We recommend it over the Python.org distribution because these third-party packages make it more immediately usable.
The course software has not yet been tested in this environment, but it likely
the only additional package needed will be pySerial
, available through the
Anaconda Navigator or the command-line conda
package manager.