Contents
Sep 1, 2017 - From Zesty on, the package names will be less confusing here: python-spyder for spyder for python 2 and python3-spyder for spyder for python.
- What is what: Python, Python packages, Spyder, Anaconda
- Test your installation
Introduction
These notes are provided primarily for students at the University of Hamburg (Germany)University of Southampton (United Kingdom)inundergraduate, postgraduate and doctoralstudies to help them install Python on their owncomputers should they wish to do so, and to support their learning ofprogramming, computational science and data science, and subsequently their studies,particular in natural sciences, mathematics, engineering, and computer science.
This is the most recent version of the installationinstructions for the 2019.(An older Version from 2014/2013, where we have used Python 2 (!) is available here.)
In short, we suggest to use theAnaconda Python distribution.
By the nature of the information provided, the information is likelyto become partially outdated over time. For reference: thismini-introduction was written in September 2016, where Anaconda 4.1was available, and Python 3.5 is the default Python provided, andrevised in March 2019, where Anaconda 2018.12 and Python 3.7.1 werethe defaults.
What is what: Python, Python packages, Spyder, Anaconda
Python
Python is
- a programming language in which we write computer programs. These programs would be stored in text files that have the ending .py, for example hello.py which may contain:
Python is also
- a computer program (the technical term is 'interpreter') which executes Python programs, such as hello.py. On windows, the Python interpeter is called python.exe and from a command window we could execute the hello.py program by typing:On Linux and OS X operating systems, the Python interpreter programis called Python, so we can run the program hello.py as:(This also works on Windows as the operating system does not needthe .exe extension.)
Python packages
For scientific computing and computational modelling, we needadditional libraries (so called packages) that are not part of thePython standard library. These allow us, for example, to create plots,operate on matricies, and use specialised numerical methods
The packages we generally need are
- numpy (NUMeric Python): matrices and linear algebra
- pandas: Python data science tools (Series and Dataframes)
- scipy (SCIentific Python): many numerical routines
- matplotlib: (PLOTting LIBrary) creating plots of data
We also use in this training:
- sympy (SYMbolic Python): symbolic computation
- pytest (Python TESTing): a code testing framework
The packages numpy, scipy, pandas and matplotlib are buildingstones of computational work with Python and widely used.
Sympy has a special role as it allows SYMbolic computationrather than numerical computation.
The pytest package and tool supports regression testing and testdriven development -- this is generally important, and particularly soin best practice software engineering for computational studies andresearch.
Spyder
Spyder (home page) is s a powerfulinteractive development environment for the Python language withadvanced editing, interactive testing, debugging and introspectionfeatures. There is a separate blog entry providing asummary of key features of Spyder,which is also available as Spyder's tutorial from inside Spyder(Help -> Spyder tutorial).
The name SPYDER derives from 'Scientific PYthon Development EnviRonment' (SPYDER).
We will use it as the main environment to learn about Python,programming and computational science and engineering.
Useful features include
- provision of the IPython (Qt) console as an interactive prompt, which can display plots inline
- ability to execute snippets of code from the editor in the console
- continuous parsing of files in editor, and provision of visual warnings about potential errors
- step-by-step execution
- variable explorer
Anaconda
Anaconda is one of severalPython distributions. Python distributions provide the Pythoninterpreter, together with a list of Python packages and sometimesother related tools, such as editors. To be precise, Anaconda is notlimited to packaging Python packages, but initially emerged to caterfor Python-based applications and packages.
The packages provide by the Anaconda Python distribution includes all of thosethat we need, and for that reason we suggest to use Anaconda here.
A key part of the Anaconda Python distribution is Spyder, aninteractive development environment for Python, including an editor.
Installation
In general, the installation of the Python interpreter (fromsource/binaries) is fairly straightforward, but installation ofadditional packages can be a bit tedious.
Instead of doing this manually, we suggest on this page to install the AnacondaPython distribution using these installation instructions, which provides thePython interpreter itself and all packages we need.
The Anaconda Python distribution is available for download forWindows, OS X and Linux operating systems (and free).
![Spyder python 3.5.2 Spyder python 3.5.2](/uploads/1/2/5/8/125805072/445346847.png)
For Windows and OS X you are given a choice whether to download thegraphical installer or the next based installer. If you don't knowwhat the terminal (OS X) or command prompt (Windows) is, then you arebetter advised to choose the graphical version. You want to installthe default suggestion (Python 3.7, 64bit), not Python 2.
Download the installer, start it, and follow instructions. Acceptdefault values as suggested.
During the installation, you have the option to install MicrosoftVisual Studio Code: You don't need to install the Visual Studio Codeenvironment for this course, but it shouldn't do any harm either.
If you are using Linux and you are happy to use the package managerof your distribution -- you will know who you are --, then you may bebetter advised to install the required packages indivdually ratherthan installing the whole Anaconda distribution.
![Python Python](/uploads/1/2/5/8/125805072/576502314.png)
(Video run through on Windows: A video summary of downloading Anaconda on Windows, including start up of spyder isavailable as a video .)
Test your installation
Once you have installed Anaconda or the Python distribution of yourchoice, you can download this testing programme andexecute it.
Running the tests with Spyder
- Start SpyderThis can be done either by typing spyder in a terminal orinside the Anaconda Prompt, or by starting Spyder through theAnaconda Navigator.
- Download thetesting file.
- Open the file in Spyder via File -> Open.
- The execute the file via Run -> Run.If you get a pop up window, you can accept the default settings andclick on the run button.
You should see output similar to this in the lower right window ofspyder (you may also see a plot appearing):
If the test program produces these outputs, there is a very goodchance that Python and the six listed packages are installedcorrectly.
Running the tests from the console
- Open a console:
- Windows: type cmd in the search box
- Mac OS X: Start the Terminal application that is located inthe Utilities folder in Applications
- Linux: start one of the shells you have available, or an xterm orso.
- Download the testing fileto your machine.
- Change directory into the folder you have downloaded the file to,and type:
If all the tests pass, you should see output similar to this:
Missing packages
If you install Python in other ways than through the Anacondadistribution and, for example, you have only installed the numpy,scipy and matplotlib package, the program's output would be:
Updating packages in the Anaconda installation
To update, for example, spyder and python, follow these steps:
- Open a terminal (see step 1 in Running the tests from the console)
- Update the conda program (this manages the updating) by typingthe following command into the console:Confirm updates if asked to do so. More than one package may belisted to be updated.
- Update individual packages, for example spyder:Other packages you may want to update include ipython,ipython-qtconsole and ipython-notebook. The relevant command wouldbe:
More details on using the conda package management system is availablein the conda documentation page.
Related tutorials
Update 12 June 2015: If you prefer a video run through of an anaconda installation, checkSteve Holden's post from June 2015