Tutorial 3 - Python IDEs, VS Code

View notebook on Github Open In Collab

This tutorial first presents several common environments and editors for Python code development, and afterward describes VS Code in more detail.

Python IDEs

An IDE (or Integrated Development Environment) is a program that integrates tools to facilitate software development, such as a code editor, tools for program execution and debugging, and source control.

In other words, an IDE is a graphical user interface for program development, that allows end-users to edit, run, browse, and debug programs from a single interface. Using an IDE is especially convenient for beginners to start editing and running codes.

Most IDEs support several different programming languages. There are some that are designed specifically for Python development (like the IDLE described below).

Also, most IDEs offer a code editor, although the code editor can be an independent software application. A code editor can be a simple text editor, or it can also allow code execution and debugging. In comparison to IDEs, code editors are simpler, but they are also less resource-demanding.

In general, IDEs offer the following basic features:

  • Save and reload code files

  • Run code from within the environment

  • Debugging support

  • Syntax highlighting

  • Automatic code formatting

The debugging support typically allows setting breakpoints in the code that stop the execution, showing variable values, and so on. For simpler debugging operations, most IDEs allow clicking on the text of an error message to quickly jump to the line of code where the error occurred, and after correcting the error, to quickly run the code.

Syntax highlighting refers to displaying source code using different colors and fonts according to the category of the written text and commands. It facilitates code writing by providing visually distinct syntax, and it can help to identify mistakes in the code.

Automatic code formatting can include features such as automated indentation, automated spacing around operators, auto-completion, etc.

Other helpful features often include: advanced text and file search options, help links or pop-up windows when hovering with the mouse over an object, selection list for object attributes (e.g., after a . press the Tab key), links to definition of objects, and similar.

IDLE

IDLE is the original IDE for Python development. It is available for Windows, Unix, and Mac OS platforms, and it comes preinstalled with the Python installation. IDLE is free, easy to use, and portable across platforms.

The name is a variation of IDE, and it is named after one of the members of the Monty Python group - Eric Idle.

To access IDLE, type in the Windows Command Prompt: python -m idlelib.idle. The IDLE window is shown in the figure below. Notice the >>> prompt in IDLE, which allows interactive programming, i.e., we can type commands and run them immediately. Also note the syntax highlighting of the entered Python statements, and the menu bar on the top of the window that is similar to the Jupyter Notebook menu and to other MS Office apps (e.g., MS Word).

IDLE is simple to use and recommended for newcomers because it simplifies some details and does not assume prior experience with system command lines. On the other hand, it is somewhat limited compared to more advanced commercial IDEs.

7201540f7b4d4d64a421f49708338667

Spyder

Spyder is a Python IDE (https://github.com/spyder-ide/spyder) which is available with the Anaconda installation, so you should have it installed on your computer. It can be accessed from the Start Program menu, as shown below. Spyder offers most of the common IDE features. An interesting feature that is not offered by many similar IDEs is the variable explorer, which displays the user data and variables in a table-based layout inside the IDE.

bc5e552c58934ccc90d73d8569ca784b

779f9161674c4528a68d3b3809101eee

Visual Studio

Visual Studio is a general-purpose IDE (https://visualstudio.microsoft.com/vs/) developed by Microsoft. It is available for Windows and Mac OS, both as free (Community) and paid (Professional and Enterprise) versions. Visual Studio provides support for program development in different programming languages. Python Tools for Visual Studio (PTVS) enables Python coding in Visual Studio. VS is a large download, but it provides excellent tools for different languages.

59c5c11308b343b7be7f6d5fbe4c5807

Eclipse and PyDev

Eclipse and PyDev is an IDE (www.eclipse.org), originally developed as a Java IDE, but it supports Python development by installing the PyDev plug-in. It is a popular and powerful IDE for Python development. It is available for Windows, Linux, and Mac OS. However, it may not be the easiest IDE for beginner programmers.

f071dbaddabe4a87a91dd6b7c2e5c81c

PyCharm

PyCharm is a fully dedicated IDE for Python (https://www.jetbrains.com/pycharm/). Available in both paid (Professional) and free open-source (Community) editions, PyCharm installs quickly and easily on Windows, Mac OS, and Linux platforms. PyCharm allows writing, running, and debugging Python code, and it has support for source control and projects.

724ca3fe7baf44fa95bd43eecc45a049

Other IDEs

Beside these, there are also other general-purpose IDEs and code editors, such as Komodo, Sublime Text, Atom, GNU Emacs, and other IDEs dedicated to Python code development, such as PythonWin, NetBeans,Thonny, and many others.

Introduction to VS Code

Visual Studio Code (VS Code) is a code editor (https://code.visualstudio.com/), available for Windows, Linux, and Mac OS. Differently from Visual Studio IDE listed above, Visual Studio Code is small and lightweight, open-source, and extensible. Installing Python support is easy, and VS Code will recognize your Python installation and libraries automatically. VS Code is built using Electron, a framework for creating desktop applications using JavaScript, HTML, and CSS. Visual Studio Code is recognized for its rapid launch speed and efficient resource utilization, guaranteeing a seamless coding experience, even with less powerful hardware.

b5b139e58c0f4dc3b0746c4a5f88e71e

VS Code Download and Installation

VS Code can be downloaded from: https://code.visualstudio.com/

782f1e23e31a4560925848ff621cb0c7

During the installation, choose all the default options.

After the installation is completed, open the VS Code, and all initial settings can be selected as defaults.

Then you will see the window similar to the following figure.

fcf15aba9bf84717adde88666f4ea7f8

Python Extension Installation and Configuration

To run Python in VS Code, we need to install the Python extension and Jupyter extension first.

On the left sidebar of the VS Code Window, click the Extension button and install the Python Extension.

f8050da3a0d84fbb9471e49af5d8d533

Similarly, search for the Jupyter notebook extension and install the extension.

6ec5336fe6844963b8c24d73e38048d5

Start Jupyter Notebook in VS Code

To start a project, it is preferred to create a new folder for the project and store all files in that specific folder.

Then, we can open the folder in VS Code and create files/scripts inside the folder.

  1. Click File and Open Folder in the upper left corner of the window to open the folder that you want to start your project in.

    70483c20458540479daf9648460c23ef

  1. There are two ways to create a new Jupyter Notebook file inside a folder.

  • Click File and then click New File, afterward choose the Jupyter Notebook option.

  • Right-click in the blank area under your folder’s name on the left side of the window to create a New File, then type your file name with .ipynb.

    843d95ae94a14f5c828255fe29af162e

  1. The first time we run a new file, we need to manually select the kernel.

    In the upper right corner of the screen, click Select Kernel to select the Python interpreter.

    We can select the default Python interpreter from our previous Anaconda installation.

    With that, the installation of Python in VS Code is completed. If any extensions are needed in the future when you run some specific scripts, VS Code will automatically show a pop-up window to help you with the installation.

ee496e9d2b514439ba96feae8973c2c6

62cedeb757ac4677a85788eac378417e

5c8e528ec2ca42b0bbe28dee3b8936f8

VS Code features

The built-in IntelliSense feature provides key functions such as:

  • Auto code completion/Assist/Hint: It predicts and auto-generates code as you type, reducing the requirement for manual input and diminishing the chances of typos and syntax errors. It offers recommendations for code elements that align with the current context, simplifying the process of producing accurate code. It also considers the programming language in use and the libraries or modules that you’ve incorporated. This results in suggestions that are closely aligned with your code’s context, facilitating the exploration of accessible choices.

  • Parameter Information: When you call a function/method, it shows information about the function’s parameters, the data types, and descriptions. This makes it simpler to provide the correct arguments when calling functions.

93d0066e91f2408c956be00a75351928

Variables/Data Viewer enables to examine and engage with the variables and data within your Jupyter notebook’s kernel. It provides a visual interface for investigating the present condition of variables, their values, and data arrangements.

5a8e68def9a642b58bcfcfacfc4cbaec

In the Data Viewer, you can sort the columns by clicking on the column name, and you can also filter the data by typing the keywords/syntax.

b6f0ebb5c9f740a6b58827f1a15def80

Run Cell Operations include:

  • Run by Line, which runs the code line by line.

  • Execute Above Cells, which runs all the cells above the current cell.

  • Execute Cell and Below Cells, which runs the current and all the below cells.

2f684edcb31247c495f0f54b529dac06

To move cells, click and hold the blue bar in front of the cell, then move to any place you prefer.

0786b1bfeee741ffb797b03bd1a5363a

Copy/Save/Zoom-in Plots.

Copy function allows you to copy the plot to your clipboard.

Save function allows you the save the plot as an image file.

Zoom-in allows you to zoom in and see the details if the plot is too large and complicated.

d8120b15900c47b7bbca1ffeb4b9f4c7

Debug features: click the arrow next to the Run Cell button and click Debug Cell, and you can then debug like you normally do in Python.

771d205352bf41989233665379792d19

BACK TO TOP