Skip to content

Effortlessly Manage Python Projects with uv: From Installation to Running in One Go!

Python is a fantastic programming language with countless fun open-source projects, such as AI tools, video processing scripts, and more. However, for many non-programmers, the biggest hurdles when trying to download and run these projects from GitHub are "dependency management" and "version management."

With terms like pip, pyenv, venv, poetry, conda—just hearing the names can be dizzying, let alone spending hours trying to get things to work. The good news is that there's a new tool called uv that is simple, fast, and reliable, especially perfect for beginners. Today, I'll guide you step by step through using uv, from installation to running a project, ensuring you can get started right away!


1. Installing uv on Windows: Done in Two Minutes

First, we need to install uv on your Windows computer. Don't worry—no complicated steps are needed; just follow along.

  1. Download and Install:
    • Open the Start Menu, find Windows PowerShell (right-click and select "Run as administrator" for better reliability).

  • Copy and paste this command, then press Enter:
    bash
    powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  • This command downloads and runs the installation script from uv's official website. It may take a few seconds to a couple of minutes, depending on your internet speed. Once done, the command line will show a message like "uv installed successfully."
  1. Verify Installation: Type uv --version. If you see something like "uv 0.x.x," congratulations—installation is successful!

After installing uv, it will sit quietly on your computer, ready to help anytime. Next, let's use it to create a new project.


2. Creating a New Project: Specify Python 3.10 and Fill in the Gaps

Subsequent commands can be run in either CMD or PowerShell. Simply clear the address bar in any folder, type PowerShell or cmd, and press Enter to open it.

Suppose you want to try an AI project that requires Python 3.10, but you might not have that version on your computer. The power of uv is that it can automatically download and set it up for you.

  1. Create a New Project Folder:
    • Create a folder anywhere, such as "myai" on your desktop, navigate into it, and open a command prompt.
  2. Create the Project and Specify Python 3.10:
    • Enter this command:
      uv init myai --python 3.10
    • uv will create a new project. If Python 3.10 isn't on your computer, it will automatically download it (may take a few minutes) and generate a virtual environment in the folder (like a separate little room just for this project).
  3. Check the Results: The folder will now have new files, such as pyproject.toml (the project's "manual") and .python-version (which records the Python version you're using).

Now you have a clean project environment—let's add some things to it!


3. Adding, Removing, and Updating Third-Party Modules: As Easy as Ordering Takeout

AI projects often need "third-party modules" (like toolkits for data processing), and uv makes this as intuitive as ordering takeout.

  1. Add a Module:
    • If the project needs numpy (a math calculation tool), type:
      uv add numpy
    • uv will add numpy to pyproject.toml and download/install it into the virtual environment—done in seconds.
  2. Remove a Module:
    • If you decide you don't need numpy, type:
      uv remove numpy
    • It will remove it from the project, clean and tidy.
  3. Update a Module:
    • Want the latest version of numpy? Type:
      uv add numpy --upgrade
    • uv will check for the latest version and update it, saving you from manual checks.

These commands automatically keep project dependencies consistent, so you don't have to worry about version conflicts. Next, let's try running a Python file.


4. Running a Python File: One-Click Launch

Suppose you write a simple test.py in your project that prints "Hello, AI!":

python
print("Hello, AI!")

Simply type:

bash
uv run python test.py

"Hello, AI!" will appear on the screen. uv automatically uses the Python 3.10 environment in your project, skipping the hassle of activating the environment. If the file has dependencies (like using numpy), uv ensures they're all in place.


5. Cloning and Running a Project from GitHub: Example with pyvideotrans

Now, let's try downloading a real project from GitHub, such as pyvideotrans (a video translation tool, available at https://github.com/jianchang512/pyvideotrans.git), and configure and run it with uv.

  1. Clone the Repository:
    • First, install Git (download from https://git-scm.com/downloads/win and follow the installation steps). After installing, reopen PowerShell or cmd.
    • In PowerShell or cmd, type:
      git clone https://github.com/jianchang512/pyvideotrans.git

Enter command in cmd

  • This downloads the project into a pyvideotrans folder in the current directory.
  1. Enter the Project Directory:
    • Type cd pyvideotrans.
  2. Initialize with uv and Specify Python 3.10:
    • Type:
      uv init --python 3.10
    • uv will check for Python 3.10 (download it if missing) and create a virtual environment for the project.
  3. Install Dependencies:
    • The project comes with a requirements.txt file listing required modules. Type:
      uv pip sync requirements.txt

Type uv pip sync requirements.txt to install dependencies

  • uv will install all dependencies from this file, such as torch, requests, etc. Note: torch is large and may take longer.

No errors, completed smoothly

  1. Run sp.py:
    • Type:
      uv run sp.py
    • If everything goes well, the project starts! You can follow its instructions to try translating videos.

Directly execute uv run sp.py to open the software

Isn't the whole process simple? uv handles complex dependency management behind the scenes, and you only need a few commands to get things done.


6. Key Features and Common Commands of uv: A Quick Summary

uv is an all-in-one tool, especially great for people like you who enjoy experimenting with GitHub projects. What makes it so powerful?

  1. Ultra-Fast Installation: 10-100 times faster than traditional tools like pip.
  2. Environment Management: Automatically creates virtual environments without manual activation; specify any Python version you need.
  3. Dependency Management: Supports pyproject.toml and requirements.txt; add, remove, and update modules with one command.
  4. One-Click Running: Use uv run to execute scripts directly, no environment setup required.

Quick Command Reference:

  • uv --version: Check uv version.
  • uv init project_name --python 3.10: Create a new project and specify Python version.
  • uv add module_name: Add a module.
  • uv remove module_name: Remove a module.
  • uv pip sync requirements.txt: Install modules from a dependency file.
  • uv run file_name: Run a Python file.