# Environment Setup 23S
## Python
The programming language used in this course is Python, with a version ≥3.10.
This guide shows the steps for installing python 3.10 for Windows, macOS and Debian Linux.
<details>
<summary> Windows </summary>
Download the installer here:
* [Windows (64-bit)](https://www.python.org/ftp/python/3.10.7/python-3.10.7-amd64.exe)
* [Windows (32-bit)](https://www.python.org/ftp/python/3.10.7/python-3.10.7.exe)
1. Open the downloaded Python installer.
**Make sure to check the "Add Python 3.10 to PATH" mark!**
<img src="https://i.imgur.com/qfydlwD.png" alt="Example Image" style="border-radius: 10px; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);">
2. Click on "Install Now". This may take a while.
<img src="https://i.imgur.com/Osksm4e.png" alt="Example Image" style="border-radius: 10px; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);">
3. To finish the installation, click "Close".
<img src="https://i.imgur.com/pViS2Ix.png" alt="Example Image" style="border-radius: 10px; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);">
### Verify Installation
To check if you successfully installed Python open up a new Terminal. Press the Windows key<kbd></kbd>, type `cmd` and hit enter.
A new terminal window opens up which should look something like this:
<img src="https://i.imgur.com/TJl9DoU.png" alt="Example Image" style="border-radius: 10px; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);">
Next, enter ``python --version`` in the terminal and hit enter.
<img src="https://i.imgur.com/A3fHfcS.png" alt="Example Image" style="border-radius: 10px; box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);">
You should see the currently installed version of Python. Any Python version higher then 3.10 is also fine.
</details>
<details>
<summary> macOS </summary>
You can install python using **either** the installer package <span style="color:red">**OR**</span> homebrew.
#### Using the installer package (.pkg)
Download the installer here
* [macOS 11](https://www.python.org/ftp/python/3.10.7/python-3.10.7-macos11.pkg)
1. Open the downloaded installer package, click on "Continue" and accept the licence

2. Click on "Install"

3. Finish the installation

#### Using homebrew
[Homebrew](https://brew.sh) is a free software package manager that can be installed by pasting the following line into the terminal (To open a terminal, press <kbd>⌘</kbd>+<kbd>Space</kbd>, type `Terminal` and hit enter)
>``/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"``
You might need to install Xcode command line tools first, by typing the following line into your terminal
>``xcode-select --install``
You can install python 3.10 by typing
>``brew update && brew install python@3.10``
**Optional**: You might want to add symbolik links like python->python3 and pip->pip3 to your Path by typing
> ``echo -n 'export PATH=/opt/homebrew/opt/python@3.10/libexec/bin:$PATH' >> ~/.zshrc``
### Verify installation
Open a terminal (To open a terminal, press <kbd>⌘</kbd>+<kbd>Space</kbd> and type `Terminal`), type `python3 --version` and hit enter.

Any Python version higher then 3.10 is also fine.
</details>
<details>
<summary> Debian </summary>
If you are using a Linux-distribution based on Debian (like Ubuntu), type the following lines into a terminal (The keyboard sequence to open a terminal in Linux usually is <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>T</kbd>):
```bash
sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10
```
### Verify python installation
```bash
python3.10 --version
3.10.7
```
Any Python version higher then 3.10 is also fine.
</details>
## Poetry
[poetry](https://python-poetry.org/docs/#installation) is a tool for managing virtual environments, installing packages, and building package distributions.
Install it using the official script:
- Linux, macOS, WSL
curl -sSL https://install.python-poetry.org | python3 -
- Windows (Powershell)
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
Check if the installation worked:
poetry -V
Optional (if poetry can not be found): Add poetry to PATH
<details>
<summary>Linux / macOS</summary>
macOS/Linux: Which shell do I have?
echo $SHELL
For **bash**
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
For **zsh**
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
Restart your terminal!
</details>
<details>
<summary>Windows</summary>
To add the directory containing `poetry` to the PATH:
- Press the Windows key and search for **path**.
- In the **System Properties** window, click on **Environment Variables...** (right lower corner).
- Then, in the upper window (User variables), choose the **Path** variable and click **Edit..**.
- Create a **New** Variable with: `%APPDATA%\Python\Scripts`.
- Restart your terminal!
After setting the path variable the `poetry install` and `poetry shell` commands should work properly.
If you get the following error message after typing `poetry shell`
...\pypoetry\Cache\virtualenvs\ecg-n-ZS_Q7z-py3.10\Scripts\activate.ps1 cannot be loaded because running scripts is disabled on this system.
You need to change the execution policy for your machine.
This can be done with the following command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
After executing this command, enter 'Y' in the terminal to actually change the policy.
</details>
## Visual Studio Code
While you can use any text editor or IDE to write your python code, we encourage you to use [Visual Studio Code](https://code.visualstudio.com/).
It provides syntax highlighting, useful keyboard shorcuts, debugging capabilities, and support for the tools you will use during this course.
### Recommended VS Code Extensions
- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) (by Microsoft)
- [Ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) (by Charlie Marsh)
- [Error Lens](https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens) (by Alexander)
- [Black Formatter](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter) (by Microsoft)
- [Coverage Gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) (by ryanluker)
- [Even Better TOML](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml) (by tamasfe)
### Recommended VS Code Settings
- Files: Auto Save -> onFocusChange
- Python > Analysis: Type Checking Mode -> basic
- Jupyter: Run Startup Commands -> `["%reload_ext autoreload", "%autoreload 2"]`