Skip to content

Instantly share code, notes, and snippets.

@gwangjinkim
Last active March 10, 2026 12:56
Show Gist options
  • Select an option

  • Save gwangjinkim/70b353e63492e2bdd37f24b441b128b4 to your computer and use it in GitHub Desktop.

Select an option

Save gwangjinkim/70b353e63492e2bdd37f24b441b128b4 to your computer and use it in GitHub Desktop.
UV Cheatsheet

cave! `–` becomes often a single hyphen. Please be aware. (You see - it is actually a double hyphen :P).

Replaces: pyenvPurposeCommand
Install a specific Python versionuv python install <version>
List available Python versionsuv python list
Use a specific Python version in a projectuv python use <version>
Automatically install the required Python versionuv run –python <version> script.py
Pin the Python version for a projectuv python pin
Replaces: venvPurposeCommand
Create a virtual environmentuv venv
Create a virtual environment with specific Python ver.uv venv –python <version>
Activate virtual environment (Linux/macOS)source .venv/bin/activate
Activate virtual environment (Windows).venv\Scripts\activate
Remove a virtual environmentuv remove
Reinstall all dependencies in the virtual environmentuv sync –reinstall
Replaces: poetryPurposeCommand
Initialize a new projectuv init <project-name>
Add a package as a dependencyuv add <package-name>
Add a dev dependencyuv add –dev <package-name>
Add a package from Gituv add git+https://github.com/user/repo.git
Remove a packageuv remove <package-name>
Lock dependencies to exact versionsuv lock
Upgrade a specific package only on `uv.lock`uv lock –upgrade-package <package-name>
Upgrade all dependencies only on `uv.lock`uv lock –upgrade
Build a Python packageuv build
Publish a package to PyPIuv publish
Replaces: pip, pipxPurposeCommand
Install a packageuv add <package-name>
Remove a packageuv remove <package-name>
Install dependencies from pyproject.tomluv sync
Install dependencies while excluding some groupsuv sync –no-group dev –no-group lint
Install dependencies from requirements.txtuv pip install -r requirements.txt
Freeze dependencies into requirements.txtuv pip freeze > requirements.txt
Generate requirements.txt from uv.lockuv export –format requirements-txt > requirements.txt
Upgrade only the `uv.lock` fileuv lock –upgrade
Upgrade all packages (`uv.lock` and execution)uv sync –upgrade
Upgrade a single package (`uv.lock` and execution)uv sync –upgrade-package <package-name>
Install CLI tools globallyuv tool install <tool-name>
List all installed toolsuv tool list
Remove a globally installed CLI tooluv tool uninstall <tool-name>
Upgrade all installed CLI toolsuv tool upgrade –all
Replaces: Python ToolsPurposeCommand
Run a Python script inside the virtual environmentuv run <script.py>
Run a script while automatically installing depsuv run –with <package> python script.py
Run a command inside the virtual environmentuv run – <command>
Run a one-time CLI tool without installing globallyuvx <tool-name> –version
Install a tool globallyuv tool install <tool-name>
Upgrade a specific tooluv tool upgrade <tool-name>
Upgrade all installed toolsuv tool upgrade –all
Enable shell auto-completion for uveval “$(uv generate-shell-completion bash)”
@arturmartins
Copy link

uv tool uninstall instead of remove.

@gwangjinkim
Copy link
Author

@arturmartins thank you!

@reneleonhardt
Copy link

Is there an official way to copy/clone a venv (same python and packages)?

cp -r .venv1 .venv2

still shows the previous VIRTUAL_ENV (obviously hardcoded in all bin scripts like activate 😄).

By the way, none of your arguments are working ( instead of --).

@ohdowon064
Copy link

uv lock --upgrade doesn't upgrade in project environment, but just update uv.lock file. so uv sync --upgrade and uv sync --upgrade-package <package_name> are correct.

@vabsalack
Copy link

@ohdowon064 is correct

@gwangjinkim
Copy link
Author

gwangjinkim commented Nov 14, 2025

@ohdowon064 @vabsalack Thank you guys! back then I believed that was true. I will correct it now. Yes - one has to use uv sync commands to execute the changes in uv.lock. Very true. - I corrected now.

@deepakmekbote
Copy link

deepakmekbote commented Jan 18, 2026

i think we will get all these from the command "uv" and can refer it instead of redundantly storing in repo?
and one more command "uv help " will give all the options.
and both gives comprehensive lists.

@gwangjinkim
Copy link
Author

@reneleonhardt Sorry for the late answer.

The official way would be not to transfer .venv manually but just to transfer pyproject.toml and uv.lock and .python-version to your new project and run uv sync for proper installation.

Ok, let's say you don't have internet access in your second computer due to security reasons.

The way would be to transform your uv.lock into requirements.txt so that you can use the mechanism of pip to transfer the wheels directly.:

uv export --format requirements.txt --output-file requirements.txt
mkdir -p wheelhouse
python -m pip download -r requirements.txt -d wheelhouse

Transfer then the wheelhouse folder and requirements.txt file to the new computer. Transfer in addition your .python-version file!

So you could try this (I haven't tested this yet):

cd my-new-project
uv init
uv pip install --no-index --find-links=wheelhouse -r requirements.txt
# update then uv.lock and pyproject.toml
uv lock --no-index --find-links wheelhouse
uv sync --no-index --find-links wheelhouse

And maybe you can tell me, if it worked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment