uv
is a high-performance Python package management tool. It not only can handle package management and dependency resolution efficiently, but also provides support for Python version management. This means you can useuv
To install and manage multiple different versions of Python. The following is useduv
Specific steps to install and manage other Python versions:
Install uv
First, you need to make sure that you have installeduv
. If you haven't installed ituv
, can be installed in one of the following ways:
Installation through official scripts(recommend):
For macOS or Linux:
curl -LsSf /uv/ | sh
For Windows (running PowerShell with administrator privileges):
powershell -ExecutionPolicy ByPass -c "irm /uv/install.ps1 | iex"
Install via pip:
pip install uv
After the installation is completed, you can use the following command to checkuv
Is it installed correctly:
uv --version
Manage Python versions with uv
Onceuv
After the installation is complete, you can start using it to manage different Python versions.
Install the specified version of Python
To install a specific version of Python, you can useuv python install <version>
Order. For example, if you want to install Python 3.12, you can execute the following command:
uv python install 3.12
This will automatically download and install the specified version of Python to your system and can use that version in your project.
View installed Python versions
You can list all installed Python versions to confirm which versions have been installed:
uv python list
Switch Python version
In a project, if you need to switch to a specific version of Python, you can useuv python use <version>
Order. For example, switch to Python 3.12:
uv python use 3.12
Create a virtual environment and specify a Python version
When you create a new virtual environment, you can use--python
Parameters specify the version of Python to use. For example, create a virtual environment using Python 3.12:
uv venv --python 3.12
This will create a name called.venv
a virtual environment and use Python 3.12 as its interpreter.
Activate the virtual environment
After creating a virtual environment, you need to activate it to start using it. Depending on your operating system, activation commands will vary:
-
For Linux or macOS:
source .venv/bin/activate
-
For Windows ():
.venv\Scripts\
-
For Windows (PowerShell):
.venv\Scripts\Activate.ps1
Synchronize dependencies
If your project already has a dependency list (for example, inDefined in the file), can be used
uv sync
Commands to synchronize these dependencies to your virtual environment:
uv sync
The advantage of this is thatuv
Will be based onThe dependencies defined in Create or update the virtual environment and install the required dependency packages.
Through the above steps, you can useuv
Easily manage and switch different versions of Python to adapt to various development needs.uv
Provides a modern and efficient way to handle common tasks in Python development, including version control and dependency management.
This is the end of this article about the summary of python uv package management. For more related python uv package management content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!