The terminal, conda, & python
Workshop 1
Learning outcomes
At the end of this session you will have a basic understanding of
- which programming languange we will use and why
- how to install and manage this “programming language” on your computer using a geeky command line interface to communicate with your computer
Programming
Why program?
- Part of Science
- Complex computations, computer models
- Tangible visualizations
- NES course modules
- Grundlagen der Optimierung
- Data Science
- Flexibilitätsmanagement
- …
- Most Master Theses
- Work after you earned your degree
How to program?
The compromise of programming languages
python
a modern, versatile, high-level programming language
- easy to read & learn
- interpreted (i.e., not compiled)
- large collection of open-source packages (‘python ecosystem’)
- cross-platform compatibility
installation and management is non-trivial
python management
Different projects require different python versions and packages
- python
- a programming language
- the python interpreter
-
a program that reads and executes python code,
available in different versions - a package
-
a ready-made bundle of code (from the python open-source ecosystem)
includes several ‘modules’, and can be part of a ‘library’ - conda
- a package and environment manager for python
- a conda environment
- an isolated and self-contained workspace where a specific version of python and required packages can be installed
Learning a new language
Programming can only be learned by regular exercise!
Ask questions!
- in a search machine (one of the most important skills in programming!)
- to your friends and colleagues
- in class and tutorium
- Using AI: be critical and cautious. (optional:) read this excellent opinion piece
The terminal
Synonyms: Command prompt, command line, console
- Some tasks can not be performed in graphical user interfaces (GUIs)
- Virtually all super computers and most web servers use Linux and need to be controlled from remote locations using terminals
Open a terminal on your computer!
What can you do in a terminal?
- Use [TAB] for auto-completion of commands and directory names
- Hit [TAB] twice to get a list of options
- current directory
.
- parent directory
..
Directories and files deleted with rm
or del
are lost forever. They don’t go to the trash, they are directly deleted.
Goal: Create a directory for our programming course at a location in your file system that suits you, for example:
/home/flo/documents/fhv/LV_scipro/
C:\Users\flo\Documents\fhv\LV_scipro
- Open a terminal and perform the following tasks from the terminal
- Change directory to the location in your file system where you want to create the new folder
- Create the new directory (pick a name that you like! I call it
scipro
for now) - Create another directory called
testdir
- Move
testdir
intoscipro
- Verify that
testdir
is listed withinscipro
- Move into
scipro
, thentestdir
, and then back out intoscipro
- Delete
testdir
In the following semester, I will refer to the directory we created above as $SCIPRO
. This is were all our exercises will live.
Learning more about the terminal and its underlying language3 could fill entire workshop days. The primer you learned here and in the brief tutorial that I prepared for you will get you through this course. If you want to dive deeper, there are many starting points and good tutorials out there, for example Ryans linux command line turorials.
Installing python on your computer
conda
- Conda
- a package and environment manager for python
- A conda environment
- an isolated and self-contained workspace where a specific version of python and required packages can be installed
- Anaconda
- an open-source distribution of conda that ships with a lot of additional software packages
- Miniconda
- a minimal installer for conda that ships with only few additonal, necessary software packages
- Channels (in the context of conda)
- are an essential part of the conda ecosystem by distributing packages and software that can be used with conda.
Installing Miniconda
- 32- or 64-bit computer
- minimum of 400 MB disk space
- Windows, mac, or Linux operating systems
- For Windows: Windows 8.1 or newer
- Admin rights (usually not possible on work laptops)
Please follow the instructions here (i.e., download and run the executable installation file).
If you want to be adventurous, execute the following commands one-by-one in your terminal
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o miniconda.exe
Start-Process -FilePath ".\miniconda.exe" -ArgumentList "/S" -Wait
del miniconda.exe
First, try to download Miniconda from the terminal. To do so, try the following commands one-by-one4
mkdir -p ~/miniconda3
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.sh
These two commands first created a directory miniconda3
in your home directory and then tried to download the installation file. If the curl
command failed, try
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -O ~/miniconda3/miniconda.sh
If either the curl
command or the wget
command successfully downloaded the installation file you can run the following commands one-by-one5. If both commands failed, please move on to ‘Approach 2’.
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh
In case both curl
and wget
commands failed to download the file, please download the installation file manually here. Make sure you choose the right bash file for your computer architecture and place it in the Downloads folder.
After the file has downloaded, run the following commands to install it (you may have to adjust the filename!):
bash Downloads/Miniconda3-latest-MacOSX-arm64.sh -b -u -p ~/miniconda3
rm -rf Downloads/Miniconda3-latest-MacOSX-arm64.sh
If that approach didn’t work either, resort to the graphical installer here.
After installing, you have to initialize your Miniconda. Try the first command, if that doesn’t work, try the second:
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh
After installing, you have to initialize your Miniconda. Try the first command, if that doesn’t work, try the second:
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
You find the comprehensive conda documentation that includes more detailed installation instructions here.
Installing Miniconda: troubleshooting
Configuring conda to use specific channels
- On Windows, open the Miniconda prompt, on Linux/Mac OS open a terminal.
- Then add the conda-forge channels with the command:
conda config --add channels conda-forge
This only needs to be one time after installation.
From now on, I will only refer to the terminal. In the context of our course, this will be the Miniconda prompt on Windows or the terminal on Linux/Mac OS.
Creating our course environment
Using your terminal, create a new conda environment named scipro2024
, which contains python version 3.11 and a number of additional packages we will need throughout the course. To do this, use the following command:
conda create -n scipro2024 python=3.11 ipython jupyterlab=4.0.6 numpy pandas scipy matplotlib
While it is totally fine to use other versions of python, I want us all to explicitly use the same version throughout this course to avoid any conflicts.
Install all the programs that you want in an environment at the same time. Installing 1 program at a time can lead to dependency conflicts.
Using your new environment
- Activate your new environment by typing
conda activate scipro2024
- Open the python interpreter
python
- Try typing something!
Recap & learning checklist
Footnotes
Synonym: Programming↩︎
Synonym: Integrated development environment (IDE)↩︎
For example,
bash
(Linux),PowerShell
(Windows), or other ones..↩︎Taken from https://docs.anaconda.com/miniconda/#quick-command-line-install↩︎
This will install Miniconda into a directory called
miniconda3
within your home directory. Talk to me if you want to change the location of the installation↩︎