Switching to uv
Switching from using pip and mise to uv .
What have I done? #
Installed uv #
curl -LsSf https://astral.sh/uv/install.sh | sh
Setup a dedicated Neovim environment #
# Create a venv for neovim
uv venv ~/.config/nvim/venv
# Install pynvim for neovim
uv pip install --python ~/.config/nvim/venv/bin/python pynvim
Set the python3_host_prog for Neovim:
-- ~/.config/nvim/lua/config/options.lua
vim.g.python3_host_prog = vim.fn.expand('~/.config/nvim/venv/bin/python')
uv commands #
Install a specific Python version:
uv python install 3.11.13
List Python versions:
uv python list
Pin a Python version for a project:
uv python pin 3.11.13
Running uv projects #
uv run main.py # filename.py
Finds or creates the project’s virtual environment, ensures dependencies are installed, runs the script in that environment.
It’s essentially doing:
uv sync # handles dependencies
.venv/bin/python main.py
Use this approach for any installed tool:
uv run ipython
uv run python -m http.server # use this for running any Python module
This is different than my previous mise/venv approach where things were configured so
that entering the directory automatically activated the virtual environment. In that case, python main.py was using the virtual env’s Python.
General workflow for new projects #
# initialize project
uv init
# add dependencies (similar to pip install)
# dependencies are saved to pyproject.toml
uv add numpy ipython
# add dev dependencies
uv add --dev pytest
# sync environment to match lockfile
uv sync