UV Practical Tutorial: Managing Research Code Environments
UV 0.13.7 Practical Tutorial: Managing Python Versions, Dependencies, and Jupyter Research Environments with a Single Tool
Python has becomeScientific data analysisPython is an essential tool for statistical computing, machine learning, and automation, but as projects grow, conflicts between Python versions, third-party libraries, and runtime environments become increasingly common. This article introduces Astral's Python tool uv, demonstrating how to install uv, manage the Python interpreter, create an isolated environment, install and lock dependencies, and perform other tasks using a data analysis project as an example. Jupyter Notebook Using the project environment in VS Code. pyproject.toml、.python-veRSion 和 uv.lockThis makes it easier to maintain a consistent project environment across different computers.
Tutorial Environment:
- Tools: UV 0.13.7
- Python: 3.12 (Example version, with compatibility with common scientific computing libraries)
- Operating system: Primarily Windows 10/11, with macOS and Linux commands included.
- Editors: VS Code, JupyterLab
- Example Project: Scientific Data Analysis and Visualization
Version Notes: uv 0.13.7 was released on November 3, 2026. This article is based on official documentation and version information available as of November 12, 2026. Subsequent versions may adjust some commands or default behaviors; it is recommended to verify before use.Official documentation。
Research projects require a dedicated Python environment.
If you have ever used Python for data processing, you may have encountered similar situations:
- One project requires an older version of NumPy, while another project depends on a newer version.
- Code that runs on one computer may result in missing modules or version conflicts when copied to another computer.
- When installing a certain image processing software, the Python environment that was working fine suddenly stopped working properly.
- The Jupyter Notebook can be opened, but the imported Python libraries are not the same versions installed in the terminal.
- After some time, when the previous analysis code was run again, the results or behavior were found to have changed.
These problems are usually not caused by the Python language itself, but by the lack of a clear, independent and traceable runtime environment for the project.
Tradition Python Environment ManagementInadequacy of the method
Common Python environment management methods include venv、pipConda and Poetry, etc.
Each tool has its own applicable scenarios, but in daily scientific research, beginners often need to work with multiple tools simultaneously:
| Tools | Main uses | Frequently Asked Questions |
|---|---|---|
| venv | Creating an independent Python virtual environment | Dependencies need to be managed using pip. |
| pip | Install Python packages | When used alone, it does not provide full project environment management. |
| Conda | Management environment and software packages | This might seem heavyweight for projects that only use Python packages. |
| Poetry | Project dependency management and packaging | It is necessary to learn its own project management system. |
| UV | Python version, project dependencies, virtual environments, and lock file management | It is necessary to understand how its project and lock files work. |
The defining feature of uv is that it integrates several commonly used Python development and environment management functions into a single command-line tool. Developed by the Astral team, it is implemented in Rust and supports Windows, macOS, and Linux.
What problems can UV light solve?
For researchers, the value of UV radiation is mainly reflected in the following aspects:
First, isolate dependencies between different projects.
Each project can have its own .venvThis prevents Python libraries installed in different projects from interfering with each other.
Second, manage Python versions.
You can specify different Python versions for different projects without having to frequently modify the system Python.
Third, record project dependencies.
By pyproject.toml Describe which software packages the project requires, and then... uv.lock Record the actual dependency versions resolved.
Fourth, reduce environmental relocation costs.
By handing over the project configuration and lock files to other members, they can recreate the environment based on the files.
Fifth, it is convenient to integrate with Jupyter.
This allows the Notebook to use the project's own Python environment, reducing interpreter inconsistencies between the terminal and the Notebook.

Install UV
uv does not require Rust to be installed beforehand, nor does it require a complete Python development environment to be configured. An official standalone installer is provided, and installation via PyPI and other methods is also supported.
Windows installation
Windows users can install it using PowerShell.
Step 1: Open PowerShell
Press Win + XChoose either “Terminal” or “Windows PowerShell”.
It is recommended to run the application with normal user privileges; there is no need to use the administrator terminal for an extended period of time just to install UV.
Step 2: Execute the installation command
If you wish to permanently install version 0.13.7 used in this article, you can execute:
powershell -ExecutionPolicy Bypass -c "irm https://releases.astral.sh/github/uv/releases/download/0.13.7/uv-installer.ps1 | iex"
This command invokes the Windows installation script provided by Astral.
If you don't want to execute the remote script directly, you can view its contents first before deciding whether to run it. The official installation documentation provides instructions on how to view the installation script.
Step 3: Reopen the terminal
After installation, close the current PowerShell window and open a new terminal window.
implement:
uv --version
If it displays something like:
uv 0.13.7
This indicates successful installation.
macOS and Linux installation
macOS and Linux users can install the program using the official shell:
curl --proto '=https' --tlsv1.2 -LsSf https://releases.astral.sh/github/uv/releases/download/0.13.7/uv-installer.sh | sh
After installation, reopen the terminal:
uv --version
Install via pip
If Python is already configured, you can also install it using pip:
pip install uv
However, if you want to use uv as a standalone Python environment management tool, you should prioritize the official standalone installer and avoid binding uv itself to a project environment.
Update UV
If installed via the official standalone installer, you can execute:
uv self update
Before updating, it is recommended to check if the current project has any special version requirements. For research projects that require long-term reproducibility, you can also retain the UV version information used at the time of the project.
Managing Python versions using UV
The Python version can affect the compatibility of third-party libraries, especially scientific computing and image processing software such as NumPy, SciPy, PyTorch, TensorFlow, and Napari.
Therefore, research projects are not advised to always use the latest Python version on the system without checking dependency compatibility.
Check available Python versions
implement:
uv python list
This command can be used to view the Python distributions that UV can recognize.
Install a specified Python version
For example, installing Python 3.12:
uv python install 3.12
UV can manage the Python interpreter and automatically retrieve the appropriate version when needed for the project.
Specify the Python version for the project
After entering the project directory, you can execute:
uv python pin 3.12
This will create or update the project directory. .python-version File.
Its content is usually similar:
3.12
After that, when uv creates an environment in the project, it will prioritize using the specified Python version.
Please note: .python-version This specifies the default Python version used by the project; it is not the same as a dependency lock file. It is also not equivalent to locking a specific Python patch version.
Example uses Python 3.12.
Starting with version 0.13.0, uv sets Python 3.15 as the default stable version. For research users, this does not mean that all scientific computing libraries should be upgraded to 3.15 immediately.
Some research software may depend on specific versions of Python, compilation toolchains, or pre-compiled binary packages.
Therefore, this article uses Python 3.12 as the demonstration environment. In actual projects, the compatibility of the required packages should be checked before deciding which version to use.
Create a scientific data analysis project
Below, we'll create a simple data analysis project to demonstrate the basic workflow of UV (Unique Visitor) analytics.
Create project folder
Open PowerShell and execute:
mkdir research-analysis cd research-analysis
The project will be named here. research-analysis。
Initialize the project
implement:
uv init --python 3.12
uv will initialize a Python project in the current directory and generate a project configuration file.
The project structure may be similar to:
research-analysis/ │ ├── .git/ ├── .gitignore ├── .python-version ├── README.md ├── pyproject.toml └── src/ └── research_analysis/ └── __init__.py
When executing a project run, synchronization, or lock command for the first time, uv also creates a virtual environment and uv.lock File.
Install commonly used Python libraries for scientific research
Suppose we need to process experimental data, create statistical charts, and perform simple data analysis.
The following software packages can be installed:
uv add numpy pandas scipy matplotlib seaborn scikit-learn
These software packages are used for:
| software package | Main uses |
|---|---|
| NumPy | Numerical computation and multidimensional array processing |
| pandas | Data reading, cleaning and organization |
| SciPy | Scientific computing, optimization and statistical methods |
| Matplotlib | Data visualization and plotting |
| Seaborn | Statistical graphing |
| scikit-learn | Machine learning and data modeling |
implement uv add Afterwards, uv will update the project dependency configuration and handle the corresponding package installations and lock file updates.
View project configuration file
Open pyproject.tomlYou can see the project metadata and dependency declarations.
The illustration is as follows:
[project] name = "research-analysis" version = "0.1.0" requires-python = ">=3.12" dependencies = [ "numpy", "pandas", "scipy", "matplotlib", "seaborn", "scikit-learn", ]
The actual file may also contain other content such as build configurations, so there's no need to delete the automatically generated UV configurations to make the file look cleaner.
pyproject.toml This section primarily describes what the project requires and which version ranges are allowed.
It is not the same as the list of software packages already installed on your computer.
Three important documents for understanding UV
Project management in UV is not just about installing software packages. What truly helps in reproducing research environments is understanding the following three documents.

pyproject.toml: Project dependency description
It records project metadata, Python version requirements, and dependency declarations.
For example:
dependencies = [ "numpy", "pandas", "matplotlib", ]
This means the project requires these packages, but the final installed versions of all dependencies are not listed here.
python-version: Python version selection
This file records the default Python version used by the project.
For example:
3.12
When a project needs to recreate the environment on another computer, uv can select the appropriate version based on this file.
uv.lock: Depends on version locking
uv.lock It is a dependency lock file automatically managed by UV, which records the actual dependency version information resolved by the project.
For example, a project might directly depend on pandas, which in turn depends on other packages like NumPy. The lock file records the complete parsing results, not just the dependencies directly declared by the project.
The official documentation clearly states thatuv.lock It contains precisely parsed dependency information and is suitable for inclusion in version control to ensure consistent dependency installation across different machines. uv
Here we need to distinguish:
pyproject.tomlWhat dependencies does the project require, and what version range is allowed?.python-version: Which Python version the project uses by default.uv.lockThe actual combination of dependency versions resolved.
These three elements together form the foundation of project environmental management.
Lock down dependencies and reproduce the environment on another computer.
For scientific research, the reproducibility of the environment is more important than simply installing software packages.
Suppose you have completed an analysis of a set of experimental data and want a colleague to run the same Python project on another computer.
Generate or update lock files
Execute the following in the project directory:
UV lock
UV will resolve dependencies based on project configuration and update accordingly. uv.lock。
Synchronize project environment
implement:
uv sync
UV synchronizes the environment based on project dependencies and lock files.
By default,uv sync Performing exact synchronization means that additional packages in the environment that are not declared dependencies of the project may be removed. For long-term projects, it is recommended to avoid arbitrarily adding dependencies to the project. .venv Installed an undocumented package. uv
Check if the lock file has expired.
Can be executed:
uv lock --check
If the project configuration changes, causing the lock file to no longer match, UV will prompt that an update is needed.
Restore environment on another computer
We recommend submitting the following files to the Git repository:
pyproject.toml .python-version uv.lock
Don't .venv The entire directory was uploaded to the code repository.
After cloning the project on another computer, navigate to the project directory:
uv sync --locked
--locked The purpose of this command is to require the current lock file to be used. If the lock file is inconsistent with the project configuration, the command will report an error instead of silently modifying the lock file.
This helps prevent collaborators from using different dependency resolution results without their knowledge.

Using UV in Jupyter Notebook
For researchers, Jupyter Notebook is a commonly used data analysis tool.
It can put code, charts, calculation results and explanatory text in the same document, which is suitable for experimental data organization, statistical analysis and visualization.
The official uv provides a Jupyter integration guide that allows Jupyter to use the project environment.
Install ipykernel
Execute the following in the project directory:
uv add --dev ipykernel
ipykernel It is responsible for enabling Jupyter to execute Notebook code using the corresponding Python environment.
Launch JupyterLab
implement:
uv run --with jupyter jupyter lab
`uv` launches JupyterLab within the project environment context. By default, the browser opens the local Jupyter page.
If the browser does not open automatically, you can check the local access address output in the terminal.
Check the Python environment in the Notebook
Create a new Notebook and enter:
import sys import numpy as np import pandas as pd print("Python path:", sys.executable) print("NumPy version:", np.__version__) print("Pandas version:", pd.__version__)
After execution, you can check the actual Python interpreter path and library version used by the Notebook.
If the interpreter path points to the project .venvThis indicates that the Notebook is using the project's environment.
Using UV environment in VS Code
If you are using VS Code, you can first execute the following in the project directory:
code.
Then:
- Open one
.ipynbFile, or create a new Jupyter Notebook. - Click the Kernel selection button in the upper right corner.
- Select Python Environments.
- Find the current project
.venvenvironment. - Make sure the interpreter path points to Python in the project directory.
In Windows, it's usually similar to this:
research-analysis\.venv\Scripts\python.exe
If the environment is not listed, please check first. ipykernel It has been installed and the VS Code window has been reloaded.
The official Jupyter integration documentation for UV also recommends installing it for your project. ipykernelThen connect the Notebook to the project's virtual environment.

Migrate the existing requirements.txt project to UV
If you have been using pip and requirements.txtThere is no need to start a project from scratch.
UV officially supports importing dependencies from existing requirements files.
Assume the existing directory contains:
old-project/ │ ├── requirements.txt └── analysis.py
First, navigate to the directory:
cd old-project
Initialize the project:
uv init --python 3.12
Then import the existing dependencies:
uv add -r requirements.txt
Final synchronization environment:
uv sync
This allows for a gradual migration from the traditional pip installation method to the UV project management method.
It is important to note that after migration, you should still check the version constraints, special installation sources, and platform limitations in the original requirements file. You cannot assume that all dependencies are completely equivalent just because the command executes successfully.
Quick Reference for Common Commands
In daily use, mastering the following commands can basically complete most Python project environment management tasks.
| Order | Features |
|---|---|
uv --version | Check UV version |
uv self update | Update UV |
uv python list | Check available Python versions |
uv python install 3.12 | Install Python 3.12 |
uv python pin 3.12 | Specify the Python version for the current project. |
uv init | Initialize the project |
uv add pandas | Add project dependencies |
uv add --dev ipykernel | Add development dependencies |
UV remove pandas | Remove project dependencies |
uv run python analysis.py | Running Python scripts in the project environment |
uv run jupyter lab | Run JupyterLab in the project environment (must be installed). |
UV lock | Generate or update lock files |
uv lock --check | Check if the lock file needs to be updated. |
uv sync | Synchronize project environment |
uv sync --locked | Synchronize with the existing lock file; do not allow automatic updates to the lock file. |
uv tree | View project dependency tree |
Common problems and troubleshooting
PowerShell prompts that the uv command cannot be recognized.
If executed:
uv --version
If the command cannot be found, you can check the following in order:
- Have you closed and reopened the terminal?
- Did the installation program complete successfully?
- Check if the UV installation directory has been added to the PATH.
- Is PowerShell currently using a different user account than it was installed?
Can be executed:
Get-Command uv
If you still cannot find it, it is recommended to rerun the official installer and check the terminal environment variables.
Dependency conflicts occurred while installing the software package.
If executed:
uv add package-name
If dependency resolution fails, you can first check:
- Is the Python version required by the project too new or too old?
- Are there any mutually exclusive package version requirements?
- Does a specific platform version of a software package need to be used?
- Did you use an incorrect package index or installation source?
You can use:
uv tree
Check the dependencies and then adjust the version constraints based on the error messages.
Jupyter cannot import packages that are already installed.
This is a problem that beginners are more likely to encounter.
For example, execute the following in PowerShell:
uv add pandas
The installation was shown as successful, but when executed in Notebook:
import pandas
However, it prompts:
ModuleNotFoundError: No module named 'pandas'
This usually indicates that the Python interpreter used by the notebook is inconsistent with the project environment.
We recommend checking the current kernel of your Notebook and selecting the following in the project directory:
.venv\Scripts\python.exe
Confirm that it has been installed. ipykernel。
Some scientific computing libraries cannot be installed correctly.
Not all Python packages depend solely on Python code.
Some packages also require:
- Specific versions of the C/C++ runtime library;
- Compiler toolchain;
- CUDA and GPU drivers;
- Pre-compiled binary packages that match the system architecture;
- A platform-specific package index.
Therefore, UV can help manage Python dependencies, but it cannot replace system-level drivers, compilation environment, and local dynamic library configuration.
In particular, for GPU-enabled tools such as PyTorch and TensorFlow, you should prioritize selecting the corresponding Python, CUDA, and platform combination according to the installation matrix provided by the software's official website.
The original code cannot run after the dependencies are updated.
It is not recommended to indiscriminately upgrade all research projects to rely on it.
If you only need to upgrade a specific software package, you can use:
uv lock --upgrade-package pandas
Then check the updated environment:
uv sync
It's best to save your original data before upgrading. uv.lockAnd the test code confirmed that the results did not change as expected.
UV compatibility with scientific research projects
UV can significantly simplify Python project management, but it is not the only option in all scenarios.
Suitable scenarios for UV protection:
- Data analysis is performed using software packages such as NumPy, pandas, and SciPy.
- Use Matplotlib and Seaborn to draw statistical graphs;
- Use Jupyter Notebook to organize experimental data;
- I need to maintain multiple Python projects;
- The goal is to reproduce project dependencies across different computers;
- Use Python to write batch processing, data cleaning, and automation scripts.
Scenarios requiring careful evaluation:
- The project relies on a large number of system-level scientific computing libraries;
- Use sophisticated CUDA, GPU, or special hardware environments;
- It relies on Conda channels provided by specific software vendors.
- The project requires a specific compiler, system dynamic library, or external service.
It is particularly important to emphasize that locking the Python package version does not equate to a complete reproduction of the entire scientific computing environment. The operating system, GPU driver, hardware architecture, external data files, random seeds, and software configuration can also affect the results.
For this type of project, UV can be used in conjunction with containers, system dependency lists, and data version management.
Summarize
For researchers who frequently use Python, environment management is an easily overlooked issue that can continuously impact work efficiency.
uv integrates Python version management, project dependencies, virtual environments, and lock files into a single workflow. It doesn't replace all research software or development tools, but it makes organizing Python projects much clearer.
If you are maintaining multiple data analytics projects, or want to organize your notebooks, scripts, and third-party libraries into a project that can run long-term and is easy to collaborate on, you might as well start with a small data analytics project to test unique visitors (UV).
In practical use, it is recommended to develop three habits:
- Each research project uses an independent virtual environment.
- Write project dependencies
pyproject.tomland retainuv.lock。 - When migrating, sharing, or publishing analysis code, record the Python version and necessary system dependencies.
These habits are more important than simply pursuing installation speed, and are also more conducive to the long-term maintenance and result reproduction of scientific research.




