Getting started with the Spyder IDE

Similar documents
College of Pharmacy Windows 10

PYOTE installation (Windows) 20 October 2017

Semester 2, 2018: Lab 1

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

Operating System Interaction via bash

Getting Started with Python and the PyCharm IDE

Clip Art and Graphics. Inserting Clip Art. Inserting Other Graphics. Creating Your Own Shapes. Formatting the Shape

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3. Installing Notepad++

Week 1: Introduction to R, part 1

The Python Mini-Degree Development Environment Guide

Writing and Running Programs

Using the Zoo Workstations

Module 1: Introduction RStudio

OU EDUCATE TRAINING MANUAL

Using Windows 7 Explorer By Len Nasman, Bristol Village Computer Club

Copyright 2018 MakeUseOf. All Rights Reserved.

Working with Basic Linux. Daniel Balagué

ADOBE DREAMWEAVER CS4 BASICS

Introduction to RStudio

Code Autocomplete Manual

Introduction to Microsoft Office 2007

COMPUTER FOR BEGINNERS

Episode 1 Using the Interpreter

Corel Ventura 8 Introduction

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

EDITING AN EXISTING REPORT

Using Microsoft Excel

Lesson 4: Who Goes There?

Sage Estimating (SQL) v18.12

DDX-R Quick Start Guide

Programming Principles 1 (CSC131) & 2 (CSC132) Software usage guide

Introduction to Programming with Python 3, Ami Gates. Chapter 1: Creating a Programming Environment

Creating Accessible Word Documents Tutorial

Intro to Microsoft Word

Windows 2000 Professional

Touring the Mac S e s s i o n 4 : S A V E, P R I N T, C L O S E & Q U I T

Project Management with RStudio

Eclipse Environment Setup

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

05: A Gentle Introduction to Virtools

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

Contents 1. OVERVIEW GUI Working with folders in Joini... 4

Installation Manual and Quickstart Guide

Microsoft Excel - Macros Explained

Aurora Multi-image System Control Software. User Manual

Assignment 1. Application Development

Joomla! 2.5.x Training Manual

ired Lite - Manual Usage The Features

The SBCC Web Publishing Process The process of creating new web pages or editing existing pages within the OmniUpdate system is straightforward.

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

Using Eclipse for Java. Using Eclipse for Java 1 / 1

Working with Images 1 / 12

The Basics of Visual Studio Code

1.0 Overview For content management, Joomla divides into some basic components: the Article

Introduction to Windows 10 Part 1

Windows XP. A Quick Tour of Windows XP Features

CROMWELLSTUDIOS. Content Management System Instruction Manual V1. Content Management System. V1

STAT 113: R/RStudio Intro

Customizing DAZ Studio

OpenForms360 Validation User Guide Notable Solutions Inc.

Adobe Dreamweaver CS3 English 510 Fall 2007

Learn Dreamweaver CS6

A Linux Virtual Machine for CS-2011 Projects

Session 1: Accessing MUGrid and Command Line Basics

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Dataflow Editor User Guide

Content Author's Reference and Cookbook

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.

Windows Computer A to Z Shortcut Key list with PDF

Lesson 4 - Creating a Text Document Using WordPad

How To Use My Alternative High

StarTeam File Compare/Merge StarTeam File Compare/Merge Help

Chapter 3 Using Styles and Templates

WORD PROCESSING ASSIGNMENT # 1 ~ FILENAME: FONTS

Game Design Unity Workshop

Magic Tutorial #1: Getting Started

Summer Assignment for AP Computer Science. Room 302

Programming with Python

MAPLOGIC CORPORATION. GIS Software Solutions. Getting Started. With MapLogic Layout Manager

File Triage. Work Smarter in Word, Excel, & PowerPoint. Neil Malek, MCT-ACI-CTT+

The Thomas Hardye School Summer Preparation Task Computer Science AS

Selecting An XML File. Boris Job Slate

Siteforce Pilot: Best Practices

Compare and Merge Track Changes

This chapter is intended to take you through the basic steps of using the Visual Basic

CS 112: Intro to Comp Prog

IT Essentials v6.0 Windows 10 Software Labs

MAME - Compilingscript V2.3a

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay.

PowerPoint Slide Basics. Introduction

Ion Client User Manual

Outlook Quick Start Guide

epad Studio Manual Process: Push the database to the scanner Inbound Pallet Outbound Storescan Settings epad Studio Manual Page 1

Performer to DP2 Hot Folder Reference Manual Rev There is only one file involved with installing the Performer to DP2 Hot Folder.

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

MS Office for Engineers

Getting Started. In this chapter, you will learn: 2.1 Introduction

Module 3: Working with C/C++

Step-by. A Very Warm Welcome to the Exciting World of Computers. Let s get Started It s easy with my Step- Instructions

How to use Excel Spreadsheets for Graphing

Transcription:

Getting started with the Spyder IDE Claudius Gräbner 1,2 1 Johannes Kepler University 2 ZOE. Institute for Future-Fit Economies Version 1.0 of July 18, 2018 Abstract Here I provide you with some basic information about the IDE Spyder, which will be used in the video lectures. 1 Getting started Spyder is an Integrated Development Environment. This means it combines many features associated with programming tasks, including: the editing of text files, the execution of code in a shell 1, the preview of figures created by your code, and much more. Therefore, IDEs are very useful for programming. While there are alternatives to Spyder, I found this to be an extremely intuitive, powerful, and freely available IDE. This document should provide you with a very first orientation such that you can use Spyder directly for the upcoming course videos. After explaining how to start a project in Spyder (section 2) we will quickly go through the most important elements of the graphical interface of Spyder (section 3), then learn how to exploit the basic functionality such as code execution (section 4) and finally have a look at how you can customize Spyder such that it serves you best (section 5). 2 Create a project and organize your files The first thing to do when you open Spyder for the first time, or when you want to start a new programming project is, well, to create a project. This means that Spyder creates a project file that stores everything you do, and lets you continue your work when you reload the project into Spyder later on. To create a project click on Projects New Project... : 1 A shell is... For example, when you open your terminal on a Mac, you are using the bash shell. 1

You then need to decide whether you want to create a new folder for your project, or use an existing one. You should definitely create the project as an empty project. After having confirmed the creation of the project, you then see the standard Spyder graphical interface, as shown below. We will now go through the most important parts of this interface one by one below, but before I want to make a comment on how to organize all the files you will be creating in the project folder during your work. It is usually not a good idea to just save everything in the project folder. This will certainly create a mess of files that will probably spoil your fun of working on your project. Rather, after setting up the project folder, it is good to provide a structure for all the files that are about to create by creating five new folders within your project folder: I A folder called src (abbreviation for source ) or code where you save all your Python scripts. I A folder called data, where you store all the raw data that you are going to process during the project.2 I A folder called output, into which you will save all the figures, tables, etc. that you are going to produce during your project I A folder called text or notes where you place all your text documents that you are writing during this project I A folder called misc, where you place all the rest, for example some slides with information somebody did send you. This then looks like this: 2 Of course, if you do not use any data as we do now in the beginning, you might skip it. 2

You do not need to follow the same convention, but you should think about a way of organizing your files in a way that helps you to keep track of what is going on in your project. Placing all files simply into one folder usually yields confusion and frustration, at least in the medium run. 3 The basis Spyder GUI Here we will quickly look at the different parts of the Spyder GUI: (i) the project explorer, (ii) the IPython console, (iii) the script editor, and (iv) the plane combining file explorer, variable explorer, and the help window: Note that you can remove a pane by either clicking on the X on its top-left corner, or by demarking it in View Panes. But more on customization below (section 5). 3.1 The project explorer Since you have created a Spyder project, your main folder and all files and folders therein will be displayed in theproject explorer: Here you can also create new folders, rename and delete files directly from within Spyder. Also, if you right-click on a folder or a file you can open it directly in your explorer. An important concept in this context is that of the working directory: the default working directory of your Spyder session is your project folder. In my example here it is called spyderintro. This means, whenever you write a relative path, the path starts from your current working 3

directory. Although it is possible to change the working directory, I can think of no situation where this is recommendable. Thus, I suggest you stay with your working directory, and use mainly relative paths. Only use absolute paths when absolutely necessary because this usually prevents your code from being used by others. /Users/graebnerc/work-claudius/general/teaching/abm-intro-dt/spyderintro/text/figs Absolute vs. relative paths Absolute paths provide the location of a file starting from the topmost directory: usually this is the root directory indicated by \, but the user directory \Users\USERNAME\ or \ also count informally as absolute paths A relative path provides the location of a file relative to the current working directory. Lets look at an example. Suppose I have a file nice-plot.pdf in the folder output, which is located in my main project folder, which is called spyder-intro : The absolute path to this would be (at least on my machine): /Users/graebnerc/work-claudius/general/teaching/abm-intro-dt/spyder-intro/ output/nice-plot.pdf The relative path would be: output/nice-plot.pdf Often, it is more useful to use relative files: as you can see from the example, using relative paths enables others to simply re-use your code once they set the same working directory. Because the file structure, user names, and other folder names usually differ across machines, absolute paths can cause problems when you give your scripts to someone else. Although quite useful, I usually remove the project explorer since the file explorer (see below) provides similar functionality. To remove the project explorer click on the top-left X of its pane. If you want to bring it back, set the corresponding mark at View Panes Project explorer. 3.2 The Ipython console The IPython console is your direct connection to Python. Here you can type in commands that are then executed. For example, typing the famous print( Hello, World! into the console and pressing enter results in Python printing the string Hello, World! : 4

Sometimes you might want to restart Python, or close the console and open a new one. You can restart Python by clicking on the top right of the console pane (the weird wheel), and then click on Restart kernel. Or you can click on Consoles Open an IPython console. There is also a tab called History log. If you click on it you see a summary of all the commands you have issued to Python in the current session. 3.3 The script editor The script editor is probably the most straightforward part of Spyder: it is an editor, comparable to Notepad, which features code coloring. Also there are some additional nice features that help you to write nice Python code, such as automatic code completion and so on. Some of the features will be described in more detail below. 3.4 File- and variable explorer, and help pane The final part concern a pane with three tabs. The first is the file explorer, which works similar than the project explorer: it lists all the folders and files in your project folder. You can open, rename, delete or move them directly. A very useful feature! The second tab is the variable explorer that lists all variables that you have defined in your current Ipython session. To the intuition type x = 2 into the Ipython console, and press enter. You should now see the defined variable in the variable explorer: This is sometimes a quite useful feature, but becomes quickly a bit overloaded. We will learn about how to define variables shortly during the main video lectures. The third tab is very helpful: whenever you call the help function, its output will be displayed here. Alternatively, you can also search the documentation from this pane directly. 4 Basic functionality We will now have a look at the most common functionality of Spyder that you are about to use. If you want to create a new script you can do so by clicking on File New file.... Then a new script pops up in the script editor. 5

You can write Python code here and then save the script by clicking on File Save or by using the adequate shortcut (CMD+S for the Mac). The most common ways to execute code refer to the following four buttons on the top of the Spyder interface: The first button is actually the least frequently used one: it executes the entire script that is currently active. The second and third button refer to a nice feature of Spyder: you can structure your script into cells. This is done by writing #%%, followed by the title of the cell. Then, all lines before the next cell definition will be wrapped into a cell, as indicated by the lines (and the code above will also be wrapped into a cell): If you click on the execution button on the middle-left, all the code in the current cell (i.e. the cell where the cursor is located) gets executed. The button on the middle-right does the same but also jumpy into the next cell. The button on the right executes the code that is currently marked, or, if not code is marked, executes the line where the cursor is currently located. Another nice feature of the editor is the possibility to add todos: If you write # TODO into the script, you will see a mark popping up at the side of the script: If you check Source Show todo list, then you get an overview over all the todos you have given you. Below, you find a list of all warnings, that Spyder issues whenever it suspects you made a coding error. 5 Customizing Spyder There are many ways to customize Spyder to your needs, and I will only go through those that I found most helpful in the beginning: 6

First, there are some general styles according to which the various panes can be allocated. For those of you who are used to RStudio: there is also an RStudio style. You can change the style View Window layouts. Just experiment a bit until you find something that you like. In case you experimented to much with the possible customization in View, you might rescue yourself by using Tools Reset Spyder to factory settings. This will undo all changes in the settings you made. Note that you can move the various panes just as you can move windows on your desktop. There are a number of useful customizations available via python Preferences. While I would not change too much here in the beginning, particularly the preferences on the editor might be useful: here you can change font size, color scheme, and much more. Keep in mind that for some preferences affecting the console to have effect, you need to restart kernel first 7