Starting Python in the DIVAS VM

Overview

Teaching: 30 min
Exercises: 0 min
Questions
  • Where and how do I write and run Python code?

Objectives
  • Understand the difference between and IDE (Spyder) and a language (Python)

  • Be able to start the Spyder IDE

  • Know where useful tabs and features of Spyder are located

Introduction to Python and the Spyder environment

Spyder is an Integrated Development Environment (IDE) used for writing/developing code. Technically, you could write your code using any old text editor (for example, nano, that we will use in the Unix shell lessons). However, an IDE like Spyder has some nice features that will make it easier to see the structure of your code, track variables, and find obvious errors/bugs.

Word Processors vs Text Editors

You DO NOT want to write your code in a word processing program like Microsoft Office. This will introduce formatting and other features that Python will not be able to deal with. Stick to Spyder or a plain text editor (saves to a .txt format)!

Starting Spyder

In the DIVAs VM, we will start Spyder from the command line.

Open a command terminal and type the command spyder and then hit enter. This will start the Spyder application. Note: depending on your settings, this may take a while.

Using Spyder and the command line

If you start Spyder in your command line as described above, your command line terminal will be occupied by Spyder and you will not be able to use it to run other commands or processes. You will need to start a second terminal to do other things.

If you want to start Spyder and leave that command line terminal available, use the command spyder &.

Useful Spyder Features

The following Spyder features/tabs/windows will be the most useful to you. You will want to set up your Spyder screen so that you can easily access them.

TheSpyderWindowLayout

Changing the layout of Spyder

You can easily change which panels Spyder shows you and where they are located. To choose to show or not show a particular panel, use the View-> Panes menu to check panels you want displayed and uncheck panels you don’t want to see. Panels can be moved to new locations by clicking and holding the panel’s top bar and then dragging it to the desired location.

Key Points

  • Spyder is an Integrated Development Environment (IDE) that makes it easier to write and debug code

  • You can write code one line at a time in the console or write longer scripts in the Editor window

  • Code should be written in an IDE like Spyder or by using a plain text editor