Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-overview
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lkluft
python-overview
Commits
7b07bbc9
Unverified
Commit
7b07bbc9
authored
10 months ago
by
Lukas Kluft
Browse files
Options
Downloads
Patches
Plain Diff
Add first rough draft
parent
d4c8ebd3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#69354
passed
10 months ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
slides.qmd
+154
-1
154 additions, 1 deletion
slides.qmd
with
154 additions
and
1 deletion
slides.qmd
+
154
−
1
View file @
7b07bbc9
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment