Spyder

Tags

Ivana's Boston
Ivana's Boston

Get yourself some Spyder

Spyder is the programming tool we'll use. It has everything you need in one download. Runs on Windows, Mac, and Linux. It's free. Free is good.

Please use Spyder 6 or later.

Download Spyder for your system. Make sure you go to the right page, and click the right download button:

Downloading Spyder

Install it. It uses lots of little files, so it might take a while.

I'll wait. Doom doom de doom doooom doom, doom de doom...

We have some wicked spiders in Australia. Yuck! They freak me out.

OK, start it up. It takes longer than I think it should, but it will get there. I'll wait.

Doom doom DOOM de doom de dooom doom, doom de doom...

Make a new project

The first thing to do when writing a new program is create a folder for the program to live. Each exercise you do should be in its own folder! Put files for different exercises in the same folder, and you'll make things harder on yourself.

You'll also make things harder on Jeremy and me. Jeremy grades many of your submissions. Make it easy for us to find the files for an exercise. A separate folder for each exercise.

Principle

Organize files

Life is easier when you organize files into subfolders.

OK, let's write a program to say hello to the universe.

Spyder uses projects, just a name for a folder with extra stuff in it. I'll show you how I create Spyder projects. It's the easiest way for me, but there are other ways. Whatever works for you is the right way to do it.

First, make a folder with Explorer (or Finder on a Mac). I prefer to make the project subfolders outside Spyder, then tell Spyder to use them. You can make project folders inside Spyder, too.

The magical Windows key

BTW, a quick way to open Explorer is Win+E. Win is the Windows key:

Windows key

From Wikimedia Commons

There are many useful Win shortcuts, like:

  • Win by itself - open start menu
  • Win+M - minimize all apps
  • Win+. - insert an emoticon
  • Win+Right arrow - snap window to screen edge
  • Win+Tab - open Task View
  • Win+V - open clipboard bin

The last one lets you see things you put on the clipboard in the past. Try it, you'll love it. (Though I prefer Ditto.)

There's lots more Win key shortcuts

Here's a folder on my D: drive. I named it hello universe py. I typed the py so I can tell it's a Python project. You don't have to do that.

Folder

This next step is optional, but it makes things easier. You'll need the path to the project folder, when you tell Spyder you want a project there. Open the project folder in Explorer. Click in the path area in Explorer, and copy the path to the clipboard:

Copy the project path

In Spyder, Projects | New project. That means click on the Projects menu entry, then the New project item.

You'll see a window like this:

New project

Click Existing directory. Directory is another name for a folder.

The only other field to change is Location. The others will take care of themselves.

Click the folder icon for Location. A dialog shows, where you tell Spyder what folder to create the project in.

Navigate to the folder you want, in the usual way. Or paste the path you copied earlier:

Paste path

Hit Enter once, and you'll navigate to the folder you pasted. Click Select Folder.

Select folder

Spyder shows you where it will make the project.

Where project made

Click Create.

Hidey hidey

In the project folder, Spyder will make a subfolder with project metadata. That's how you tell it's a Spyder project.

Metadata

Adela
Adela

I don't see that folder.

It might be hidden. Folders with a . in front are usually hidden, though not always.

I've set Explorer to show hidden stuff:

View options

I recommend you do the same, but it's up to you. (This screenshot is from Windows 10. Win 11 is different. Mac is... I dunno.)

I strongly recommend you show file extensions as well. Just from the next screenshot, what type of file is hello universe?

No extensions

Ethan
Ethan

Can't tell, just from that.

Right. Turn on show file extensions, though...

Extensions

... the py tells you it's a Python file.

View file extensions is here:

View options

Spyder display

Let's take a look at the display. Spyder starts out like this:

Default look

I don't like dark mode or the default pane layout. I used the Preferences button, and changed the Appearance from Spyder Dark to Spyder. Of course, you should use what you prefer.

I also like to see the project pane. That's under View | Panes.

Here's what I ended up with:

Panes

The project pane shows all the files in your project. Add a file to the project's folder with Explorer or Finder (or Spyder), and it will show up here.

The editor pane is where you'll type your code. There's always at least one file open in the editor pane. Spyder makes an annoying temp.py tab. When you create a file, you can close it.

The console is for input and output. That's where you'll type the input your program needs, and where you'll see your program's output.

The multipurpose pane shows a bunch of different stuff, depending on what tab you're looking at. The most useful one is the Variable Explorer. You'll use it a lot when debugging. It will save your sanity.

Back in the day, we didn't have debuggers. That's one of the reasons I'm crazy.

Make your first Python program

To make a new python file, right-click on the project name, then New, then Python file.

New Python file

Type in the file name. It will automatically be given the extension .py, which is what you want. All Python programs should have a .py extension.

OK, there are exceptions, but they don't matter to us.

Here's what I ended up with.

A new file

Spyder insists on having files like temp.py in the editor. Close them.

Also, erase the default comments in your program. Later, you'll be learning how to use comments.

Type this code into your program. This one time, type it in, don't copy and paste. From now on, though, copy-and-paste when you can.

  • print('Hi there, universe!')

As you type, you'll see some of Spyder's cool features, like autocompletion.

Autocompletion

As you type something Spyder recognizes, it will offer suggestions for what you might mean. Hit Tab or Enter to accept the suggestion.

To learn more about Spyder, get a tour from the Help menu. There are many videos and other things.

When you're finished typing the line, save the file. I use the shortcut Ctrl+S. Shortcuts save time.

Run the program

There's a run button on the toolbar, a green arrow, or you can press F5 on Windows. If you're asked, run the program using the default configuration.

You should see Hi there, universe! in the console.

Argh! I accidentally closed a pane!

It's easy to accidentally close a pane. Don't panic! You'll be OK.

Use the View menu to open and close panes. If you really get stuck, there's Tools | Reset Spyder to factory defaults.

If the console gets too messy for you, clear it with Ctrl+L.

Remember to email me pet photos if you want them on this site.

Summary

  • Make a new folder for every project.
  • We'll use Spyder to do our Pythony work.
  • Spyder has shortcuts, and groovy tools like autocomplete to make your life easier.
  • Easy is good.
  • If you mess up your display, it's easy to get back to what you want.
  • Send me pet photos.