LM Jupyter

Working with Jupyter (Uni Marburg Environment)

Python can be used in many development environments such as Visual Studio Code, PyCharm, Thonny, or Jupyter.

In this course, we primarily use JupyterLab provided by Philipps-Universität Marburg. JupyterLab runs in a web browser, requires no local installation, and gives you access to a Python console, a text editor, a terminal, and your personal files.

We begin with two different ways of running Python:

  1. entering one instruction directly in the Python console, and
  2. saving instructions in a Python script and running the complete file.

Understanding this difference is an important first step toward writing programs correctly.


Accessing Jupyter at Uni Marburg

You can access Jupyter directly through your browser:

Open Jupyter Uni Marburg

Log in with your university account to access your personal workspace.

Within Jupyter, you can:

  • try individual Python instructions in a console,
  • create and edit Python files (.py),
  • execute complete Python scripts in a terminal,
  • save and organize files and folders.

What Is JupyterLab?

JupyterLab is the working environment that you see in your browser. Python is the programming language, and the Python interpreter is the program that reads and executes your Python instructions.

The main areas of JupyterLab are:

  • File Browser: shows your folders and files.
  • Launcher: opens tools such as a console, text editor, or terminal.
  • Python Console: executes one instruction at a time and immediately displays the result.
  • Text Editor: lets you write and save a program as a .py file.
  • Terminal: accepts operating-system commands and can start the Python interpreter for a complete script.

Step 1: Try Python in the Console

First, use the interactive Python console. It is useful for trying short instructions and seeing the result immediately.

  1. Open the Launcher in JupyterLab. If it is not visible, select File → New Launcher.
  2. In the Console section, select the available Python 3 console.
  3. Enter the following instruction at the prompt:

    print("Hello")
    
  4. Press Shift + Enter to execute it.

The console should display:

Hello

What Happens Here?

  • print is a built-in Python function. It tells Python to display something.
  • The parentheses () contain the information passed to the function.
  • "Hello" is text. Text must be enclosed in quotation marks and is called a string.
  • The Python interpreter reads the instruction, executes it, and sends the result back to the console.

The console is interactive: you enter an instruction and receive an immediate response. This is useful for experimenting, but a program that should be saved and executed again belongs in a Python file.


Step 2: Create a Python Script

A Python script is a plain text file containing Python instructions. Python scripts use the file extension .py.

  1. In the JupyterLab menu, select File → New → Text File.
  2. Rename the new file to:

    hello.py
    
  3. Enter this Python instruction in the file:

    print("Hallo Welt")
    
  4. Save the file with Ctrl + S or File → Save.

The .py extension identifies the file as a Python script. The file now stores your program permanently and can be executed as often as needed.


Step 3: Run the Script in the Jupyter Terminal

Now ask the Python interpreter to read and execute the saved file.

  1. Open the Launcher and select Terminal.
  2. Make sure that the terminal is in the folder containing hello.py. You can display the files in the current folder with:

    ls
    
  3. Check which Python command is available and which version it starts:

    python --version
    

    If this command is not available or does not report Python 3, try:

    python3 --version
    

    The terminal should display a version beginning with Python 3, for example:

    Python 3.12.3
    

    The exact version number may be different. For this course, the important part is the major version 3.

  4. Use the command that reported Python 3 to run the script. If python --version reported Python 3, enter:

    python hello.py
    

    If python3 --version reported Python 3, enter instead:

    python3 hello.py
    
  5. The terminal should display:

    Hallo Welt
    

The command consists of two parts:

  • python or python3 starts the Python 3 interpreter.
  • hello.py tells the interpreter which file to execute.

Python reads the script from top to bottom and executes each instruction in order. If you edit the file, save it before running the command again; otherwise, Python will execute the previously saved version.

You may sometimes see a command such as python3 *.py. The asterisk * is a wildcard that can match several Python files in the current folder. It does not mean “insert a filename here.” When learning and when working on a specific program, use the exact filename instead:

python3 hello.py

This makes it clear which script Python should execute and avoids accidentally passing additional filenames to the program.


Console and Script Compared

Python console Python script
Instructions are entered interactively Instructions are stored in a .py file
Results appear immediately The complete saved file is executed
Useful for short tests Suitable for reusable programs
Previous input is session-oriented Code remains available as a file

Professional programming usually means writing reproducible code in files. The console remains useful for quick tests and for understanding individual instructions.


Saving and Downloading Your Python File

Files saved in JupyterLab remain in your university workspace. To keep an additional copy on your computer:

  1. Select hello.py in the File Browser.
  2. Right-click the file and select Download.
  3. Store the file in a folder where you can find it again.

Summary

In this course, JupyterLab Uni Marburg serves as the primary programming environment. You have used two ways of executing Python:

  • In the console, Python executes an instruction interactively.
  • In a Python script, instructions are saved in a .py file and executed through the terminal.

This distinction helps you move from trying individual commands to writing complete, reproducible programs.

Open Jupyter Uni Marburg


Running Python Scripts on Windows Without Development Tools

You do not need JupyterLab, Visual Studio Code, PyCharm, or another specialized development environment to run a Python script on Windows. If Python 3 is installed, a plain text editor and a Windows terminal are sufficient.

1. Create and Save the Script

Open a plain text editor, enter the following code, and save the file as hello.py:

print("Hallo Welt")

Make sure that the file is really named hello.py and not hello.py.txt. Windows may hide known file extensions by default. You can enable File name extensions in Windows File Explorer to check the complete filename.

2. Open a Windows Terminal

You can use either of these standard Windows tools:

  • Command Prompt (cmd)
  • PowerShell

Open the Start menu, type cmd or PowerShell, and start the application. No programming editor or IDE is required.

3. Navigate to the Script

Use cd to change to the folder in which you saved hello.py. For example:

cd C:\Users\YourName\Documents\Python

If a path contains spaces, place it in quotation marks:

cd "C:\Users\YourName\My Python Files"

You can use dir to display the files in the current folder and check that hello.py is present:

dir

4. Check Python and Run the Script

First, check whether Python 3 is available:

python --version

On Windows, the Python Launcher may also be available:

py --version

Then run the script with the command that reported Python 3:

python hello.py

or:

py hello.py

The terminal should display:

Hallo Welt

If Windows reports that python or py is not recognized, Python may not be installed or may not have been added to the system path. In that case, install Python first or correct the Python installation before trying to execute the script again.

Although a .py file can sometimes be opened by double-clicking it, running it from a terminal is preferable while learning. The terminal keeps the program output and possible error messages visible, making it easier to understand and correct the program.

Updated: