Python in Spyder#

What is an IDE? “An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools and a debugger” (Wikipedia).

An IDE can include features like syntax highlighting, code completion, version control, and debugging. There are a WIDE range of IDEs that are proprietary or open-source, tailored to a specific language or able to work across languages.

Some common IDEs include Eclipse, Geany, Brackets, PyCharm, Spyder, RStudio, etc. For more in IDEs, visit Wikipedia’s “Comparison of integrated development environments” page.

Before we get started in Python, we’ll need an IDE! We’ll be using Spyder, “ a free and open source scientific environment written in Python, for Python, and designed by and for scientists, engineers and data analysts” (Spyder documentation).

Setup#

To install Spyder as a stand-alone program: spyder-ide.org

Lecture#

Panopto logo Python in Spyder

Getting Started With Spyder#

Spyder has three default panes that show up when you launch the program. Your .py file shows up on the left-hand side of the program window. This is where you will write Python code. You can have multiple .py files open in Spyder and navigate between the tabs.

The top-right pane has four default options:

  • Variable explorer, which lets you see named variables in your program

  • Help, which provides additional documentation, information, or resources

  • Plots, which will show visualizations generated by your program

  • Files, which will show all files currently open or active in your Spyder workspace

The bottom-right pane is the Console, which lets you execute and test Python commands. You can have multiple consoles open simultaneously. So how is the Console different from your .py file?

In the .py file you are writing a Python program that will run or execute when the file is called. You make updates to that file, save changes, etc. The Console lets you execute Python commands but is not saving those commands as part of a .py file. Great for testing. Less great for building out complex programs.

When we were working in Replit, all files that were part of our Python project were in the same virtual workspace. That’s not going to be the case when working in a desktop IDE like Spyder. Think of this as the difference between working with files in Google Drive versus on your local computer.

You can set a working directory, which is where Spyder will look for external files you are wanting to access from within a Python program. The working directory is also where Python will save .py files you build.

Click on the folder icon in the top-right hand corner of Spyder (next to the arrow icon) to set a working directory. It doe–where you save .py files and other files (think data files) you might be wanting to access as part of a Python program.

Now, files don’t have to be in your current working directory for you to access them in Python. But you’ll need to provide the full file path (i.e. location information or directory information for where that file is located on your computer).

Go ahead and create an EoC folder and set that folder as your working directory in Spyder. It might also be a good idea to start creating lab-specific sub-folders within your EoC parent folder. This will help with organization as we move through labs and work with a variety of sample files and datasets.

Application#

Work through the “First Steps with Spyder”resources provided in the Spyder documentation. That includes two 3.5 minute videos that introduce you to the basics of the Spyder IDE and how to get started with Python in Spyder.