Skip to content
Snippets Groups Projects
Unverified Commit 7b07bbc9 authored by Lukas Kluft's avatar Lukas Kluft
Browse files

Add first rough draft

parent d4c8ebd3
No related branches found
No related tags found
No related merge requests found
Pipeline #69354 passed
......@@ -11,4 +11,157 @@ author:
- name: Lukas Kluft
---
# Of pythons and other snakes
# Python
* Invented by Guido van Rossum in XXXX
* Usually considered to have a simple syntax
* Interpreted scripting lanuage
* De-facto standard in many data science fields
## Interpreter
* Python is not compiled^[this is true but also not true] but interpreted on runtime
* The interpreter can be called directly
```{raw}
python3 my_scripy.py
```
* Scripts can define an interpreter in the shebang
```
#!/usr/bin/env python3
```
# Standard library
* Python organizes code in individual packages
* [Standard library](https://docs.python.org/3/library/index.html) provide extensive built-in facilities (`os`, `sys`, `datetime`, `itertools`, ...)
# External packages {auto-animate=true}
* The python package index ([PyPI](https://pypi.org)) is a centralized repository for third-party packages
* Everyone can register packages under a not yet taken name (first come first serve)
* Packages can be installed using the built-in package manager pip:
```{raw}
python3 -m pip install numpy
```
# Package manager
* A package manager is a software that helps you to manage different version of packages and their dependencies
* General purpose package manager (`brew`, `apt-get`, `conda`, ...)
* Python package manager (`pip`, `conda`, ...)
# _Virtual_ Environments
* Manage different sets of python packages
* Allows you to have a stable combination of package versions
* Pure python tools (`virtualenv`, ...)
* Tools to handle general software environments (`conda`, ...)
# (Ana)conda
* `conda` is a general purpose package manager provided by Anacond Inc.
* `conda` allows you to install
1. handle virtual environments
2. with different python interpreters
3. and install python packages
# Fastest snakes on earth
:::: {.columns}
::: {.column width="30%"}
Python
* Foo
* Bar
:::
::: {.column width="30%"}
Anaconda
* Very big
* Slow
:::
::: {.column width="30%"}
Mamba
* Venomous
* Fastest snake
:::
::::
# (micro)mamba
* `mamba` is a drop-in replacement for `conda` written in C++
* Conflict resolution is **much** faster
* Can be installed without any pre-occupied environment (`micromamba`)
# Setting up an environment
```{raw}
mamba create -n my_env python=3.12
mamba activate my_env
mamba install matplotlib numpy scipy
```
# Recreating an environment {auto-animate=true visibility="uncounted"}
Specify environment name, python version and dependencies:
```{.yaml filename=environment.yaml}
name: my_env
channels:
- conda-forge
dependencies:
- matplotlib
- numpy
- scipy
```
Create a new environment based on your configuration:
```{raw}
mamba env create -f environment.yaml
mamba activate my_env
```
# Recreating an environment {auto-animate=true}
Specify environment name, python version and dependencies:
```{.yaml filename=environment.yaml}
name: my_env
channels:
- conda-forge
dependencies:
- matplotlib
- numpy
- scipy
- pip:
- gribscan
```
Create a new environment based on your configuration:
```{raw}
mamba env create -f environment.yaml
mamba activate my_env
```
# Excursion: Ipython kernels
* Make an environment usable in Jupyterhub
* Install `ipykernel` package to manage different kernels:
```{raw}
python3 -m pip install ipykernel
```
_(alternatively specify in your `environment.yaml`)_
* Install the currently active (!) environment as kernel:
```{raw}
python3 -m ipykernel install --name my_env
```
* The current environment should be available as kernel in Jupyter
# Conclusions
* Use virtual environments to organize your work
* Keep track of installed packages in an `environment.yaml` file
* If in doubt, use `micromamba` to do so
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment