Dark theme

Python


The best way to write and run Python scripts is using an install called "Anaconda".

Python itself comes as a set of software which can be downloaded from the Python website, but there are also a wide variety of libraries that almost anyone working with Python will want, along with software to help you write code (called "Integrated Development Environments" or IDEs). Anaconda bundles all these up with the core Python software in a way that makes it very easy to use.

First and foremost, Python comes in two, incompatible, versions: 2 and 3. Anaconda installs both, and lets you flip between them (same for Jupyter/iPython Notebook), but uses one version as the default. It is better to get used to 3 if you are starting, as this is the latest. You can find a list of the differences here -- you will eventually need to get your head around them as there is plenty of old version 2 code out there.


Anaconda is installed in our labs, so if you're working there you won't need to install anything else. If you're at home, and you don't yet have Anaconda, download it and install it following the instructions:

When it installs, make a note of where it is installing. It will ask you whether you want to set up the PATH or not. This is a list of where to look for programs. Tick this (despite the warnings) to say yes. This will make things simpler in the long term.

Once Anaconda is installed, you should be able to open a command prompt/terminal and type:
python --version
and it should show the Python version if installed properly. If it comes back saying it can't recognise that name, it probably hasn't installed correctly in the PATH.


To manually add Anaconda to the PATH on Windows, follow these instructions to edit the PATH (you'll need administrator rights), and add the directory where Anaconda installed, e.g. c:\Program Files\Anaconda\. Don't forget to add a ; between this new entry and any other entries currently in the PATH.

To manually add Anaconda to the PATH on Macs or Linux, follow these instructions to edit the PATH (you'll need administrator rights), and add the directory where Anaconda installed, e.g. ~/User/yourname/anaconda. Don't forget to add a : between this new entry and any other entries currently in the PATH.

You may find that some elements like IDLE don't work from the command line if the PATH hasn't set properly. However, you should be able to start all this from the start menu. If you have a choice, use Python 35 (3.5) versions rather than Python 27 (2.7) versions from the menu.


If, later on in your coding, you need to update Anaconda's libraries, type:
conda update --all
This may not update Python, in which case, try:
conda update python
To install a major Python update, use, e.g.:
conda install python=3.6
Failing this, uninstall Anaconda and install a new version. To uninstall Anaconda, use the Uninstall-AnacondaX.exe program in the install directory.