Running code from a command line interface
Latest Page Update: 23-09-2026
Running python scripts from the terminal¶
While Jupyter notebooks are nice for rapid prototyping and sharing code, they are rarely used in production. Therefore, we advice you to become familiar with also running python scripts from the command-line.
In order to create a python script, you just create an empty file with the extension .py, and write the code as you are used to.
Running a python script from a terminal
- Create a folder for the weeks exercise somewhere, e.g. ex10_VJ
- Download the exercise data zip and extract it into the directory (e.g. ex10_VJ), such that you have a folder called ex10_VJ/data
- Create your scripts in the root, e.g. ex10_VJ/my_part_1.py and begin coding
- Open a terminal: Mac users can search for
terminalas they search for all other apps. Linux-users, you're on your own ;-) - Change the working directory to the exercise root: Enter
lsand press enter to see the current path printed, usecdto change the working directory, e.g. `cd
To run a python file, in the terminal with the path set you:
- Activate your conda environment in the terminal:
conda activate course02503(once is enough) - Execute a python script by writing
python3 my_script.pyand pressing enter.
- Create a folder for this weeks exercise somewhere, e.g. ex10_VJ
- Download the exercise data zip and extract it into the directory (e.g. ex10_VJ), such that you have a folder called ex10_VJ/data
- Create your scripts in the root, e.g. ex10_VJ/my_part_1.py and begin coding
- Open a
cmdterminal: you can press Windows key + r and entercmdand press enter - Change the working directory to the exercise root: Enter
dirand press enter to see the current path, usecdto change the working directory, e.g. `cd
To run a python file, in the terminal with the path set you:
- Activate your conda environment:
conda activate course02503(once is enough) - Execute a python script by writing
python3 my_script.pyand pressing enter.
Path consistency
In general, we advice you to always run scripts from the exercise-root. In this way, you always know that path to contents of data-folders will always be of the form data/<your_image.png/jpg>.
If you want to stick with Jupyter notebooks¶
Remember that you can always call python functions by executing
!python3 your_file.py
in a code cell.