Stop Using Pip - This New Tool is 100x Faster (UV Tutorial)
Table of Contents
Introduction
This tutorial introduces you to UV, a Python package and project manager that promises to be significantly faster than Pip. If you're currently using Pip or manually managing your virtual environments, transitioning to UV can streamline your workflow and improve your coding efficiency. We'll walk you through the installation and setup process, as well as how to use UV for both scripts and projects.
Step 1: Install UV
To get started with UV, follow these steps for installation:
-
Visit the UV Installation Documentation
Go to the UV installation page: UV Install Docs. -
Choose Your Installation Method
You can install UV using pip. Open your terminal and run:pip install uv
-
Verify Installation
Confirm that UV is installed correctly by running:uv --version
Step 2: Setting Up Python Versions
UV allows you to manage different Python versions seamlessly. Here’s how to set them up:
-
Check Available Python Versions
Run the command to list all available Python versions:uv pyenv
-
Install a Specific Python Version
To install a specific version, use:uv install <version>
Replace
<version>
with the desired Python version number. -
Set a Default Python Version
To set a default version for your projects, use:uv set <version>
Step 3: Using UV for Scripts
Using UV for scripts can enhance speed and efficiency. Follow these steps:
-
Create a New Script
Start by creating a new script file. For example:uv create-script my_script.py
-
Add Dependencies
Specify any dependencies required for your script in arequirements.txt
file. -
Run Your Script
Execute your script with UV:uv run my_script.py
Step 4: Using UV for Projects
UV can help manage entire projects efficiently. Here’s how to set it up:
-
Initialize a New Project
Create a new project directory:uv create-project my_project
-
Navigate to Your Project Directory
Change to your project directory:cd my_project
-
Add Dependencies
Create arequirements.txt
file and list your project’s dependencies. -
Install Dependencies
Use UV to install all dependencies specified:uv install
-
Run the Project
Launch your project using:uv run main.py
Conclusion
Transitioning from Pip to UV can significantly enhance your Python development experience, especially in terms of speed and efficiency. By following the steps outlined in this tutorial, you can install UV, set up Python versions, and effectively manage scripts and projects.
For further exploration, consider checking the official UV documentation for advanced features and best practices. Happy coding!