Using Third-party libraries
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)
Few installation methods¶
Traditional workflow with venv and pip¶
python3 -m venv venv-for-something
. venv-for-something/bin/activate
pip install numpyor in a project with a requirements.txt file:
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txtTraditional workflow with conda¶
conda create -n venv-for-something
conda activate venv-for-something
conda install numpyUV in a project using UV¶
In a project using UV, one can run
uv sync
. .venv/bin/activatePixi in a project using UV¶
In a project using Pixi, one can run
pixi shellNew environment using UV¶
Following the traditional workflow
uv venv .venv -p 3.13
. .venv/bin/activate
uv pip install numpyStandard UV workflow:
uv init
uv add numpy
. .venv/bin/activateNew environment using Pixi¶
pixi init
pixi add numpy
pixi shellEnvironments with install-locked-env¶
install-locked-env is a tool that install locked environments in a local directory. It uses UV or Pixi so it is very fast. It can be used for example to install locally the main environment of this Python training:
uvx install-locked-env https://foss.heptapod.net/py-edu-fr/py-edu-fror to install a good environment to work with the Computational Fluid Dynamics framework Fluidsim:
uvx install-locked-env https://github.com/fluiddyn/fluidsim/tree/branch/default/pixi-envs/env-fluidsim