Using Third-party libraries#

Education objectives

  • notion of third-party Python libs

  • good/bad practices

  • lock files and reproducibility

  • established and emerging tools

You want to use Python to execute your own Python code that require third party projects. You have many choices to do this!

General recommendations#

We can give general advices:

Not recommended

  • Installing packages in the system Python

  • Installing packages in the base Python of conda installation

Recommended

  • Use virtual environments

  • When possible, use modern workflows with lock files (i.e. tools like PDM, UV, Pixi)

Tip

Lock files are really a game changer, in particular for reproducibility. Use them when possible!

Few installation methods#

Traditional workflow with venv and pip#

python3 -m venv venv-for-something
. venv-for-something/bin/activate
pip install numpy

or in a project with a requirements.txt file:

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

Traditional workflow with conda#

conda create -n venv-for-something
conda activate venv-for-something
conda install numpy

UV in a project using UV#

uv sync
. .venv/bin/activate

Pixi in a project using UV#

pixi shell

New environment using UV#

Following the traditional workflow

uv venv .venv -p 3.13
. .venv/bin/activate
uv pip install numpy

Standard UV workflow:

uv init
uv add numpy
. .venv/bin/activate

new environment using Pixi#

pixi init
pixi add numpy
pixi shell

Todo

Add more explanations on lock files and reproducibility.