uv (and direnv)¶
These instructions install uv and direnv in your home directory.
uvis a very fast and powerful Python installer, package manager and virtual environment manager written in Rust.direnvis a shell extensions that automatically loads or unloads environment variables when you enter or leave a directory. This allows you to activate or deactivate a Python virtual environment when entering or leaving a directory.
In this tutorial, you’ll use uv to create a virtual environment with a specific Python version, and install the numpy package.
Install uv¶
Install uv in your $HOME/.local/:
curl -LsSf https://astral.sh/uv/install.sh | sh
Ensure that $HOME/.local/bin is included in your PATH (e.g. .bashrc).
Install direnv¶
Install direnv in your $HOME/.local/:
curl -sfL https://direnv.net/install.sh | bash
Add the following line to your shell startup file (e.g. ~/.bashrc):
eval "$(direnv hook bash)"
Reload your shell afterward, or manually execute this line in your current shell.
Setup a Python Virtual Environment¶
The following instructions give some ideas on how to use uv.
- create a directory
numpy_projectand set the python version in the virtual environment to 3.14:
uv init numpy_project --python 3.14
- in the directory
numpy_projectcreate the virtual environment:
cd numpy_project
uv venv
- enable the automatic activation of the virtual environment with
direnv:
echo "source .venv/bin/activate" > .envrc
direnv allow
- add
numpyto the virtual environment:
uv add numpy
- test the setup:
python --version
python -c "import numpy; print(numpy.__version__)"
That’s all folks!