Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Different ways to use Python

We present here different ways to run Python programs, from the most accessible to the most flexible.

In the first part of this training, we used JupyterLite to run Python directly in the browser — no installation required. This is convenient for learning, but a Python developer also needs to be able to run Python locally, understand which interpreter is active, and work efficiently from the terminal or an IDE.

This section walks through the main approaches: running scripts from the terminal, working interactively with IPython, editing code in an IDE, and using JupyterLab for notebook-style workflows.

Notebook Cell
import os

os.chdir("../common/examples")
The history saving thread hit an unexpected error (OperationalError('no such table: history')).History will not be written to the database.

Python: a language and some interpreters

Python is a programming language.

The most common way to execute Python code is to interpret it. Through misuse of language, one says that Python is an interpreted language (like Bash, Matlab, and in contrast with Fortran, C or C++). To interpret code, we need an interpreter, i.e. a program parsing Python code and running computer instructions.

The interpreter is a program, which is somewhere is your computer. The program is associated with a command (typically python or python3) that one can use in the terminal without giving the full path.

Most of the time, users of Python software don’t need to know where is the interpreter. However, as a Python developer, it is usually good to have an idea about which interpreter is used.

Execute a script with the command python3

Work interactively with IPython

The command ipython launches the program IPython, which is used for interactive python.

Python in an IDE (Visual Studio Code)

Launch the application Visual Studio Code, a lightweight IDE (Integrated Development Environment).

VSCode is first a very good code editor with:

For this training we will mostly use this feature, but VSCode is actually much more than that.

Python in the browser (JupyterLab)

Jupyter is a very powerful tool to present results (see these examples). For example, the presentations of this python training are made with Jupyter Notebooks.

Let us launch Jupyter Lab with the command:

jupyter-lab

This should start a server and maybe also open the corresponding application in your browser. If the application does not automatically starts, use one of the http addresses given in the terminal.