Updating to uv from pip

Posted on Fri 11 April 2025 in uv, pip, python • Tagged with uv, pip, python

This is a short guide on how to upgrade a project from using pip with a requirements.txt file to using Astral's uv. It assumes that uv is already installed and that you have a project set up with a requirements.txt file.

Initialize uv:

uv init

Remove hello.py.

rm hello.py

Modify project.toml to update the information about the project.

Add the dependencies from requirements.txt to the project.toml file:

uv add -r requirements.txt

That's it! You can now use uv to manage your dependencies. You can run the project with:

uv run your_script.py

Alternatively, you can use uv sync to manually update the environment then activate it before executing a command:

uv sync
source .venv/bin/activate
python your_script.py

To add new dependencies, you can use the uv add command:

uv add package_name

To upgrade a package, you can use the uv upgrade command:

uv lock --upgrade-package package_name

Using uv to run Python tools without installing them

Posted on Thu 23 January 2025 in python, uv • Tagged with python, uv

I wanted to run a Python tool without installing it, or preparing a virtual environment and all that. This is now very easy with uv, using uvx.

I wanted to run markitdown, a tool to convert various files to Markdown. I didn't want to install it, so I used uvx:

uvx markitdown "file_to_convert.docx" > output_file.md

It downloads the tool and installs it in a temporary, isolated environment.

A tool can be installed with uv tool install, like this:

uv tool install markitdown

It's very convenient.