Don't create virtual environment python in 2025

Krish DesaiKrish Desai
5 min read

For years, the first step in any Python project, big or small, has often been the same opening your terminal and typing something like python -m venv venv . This manually creating virtual environments has become so ingrained that it feels like a mandatory part of the Python development lifecycle. But what if I told you that in the near future, this step could become a thing of the past?


Inroduction of uv

An extremely fast Python package and project manager, written in Rust. uv is presented as a modern tool that aims to revolutionize the way you manage Python projects and their dependencies. It introduces a new ecosystem for Python project management that is designed to be more organized and efficient.


Uv features

uv provides essential features for Python development — from installing Python and hacking on simple scripts to working on large projects that support multiple Python versions and platforms. When you come from the JavaScript ecosystem, it is similar to npm.

uv's interface can be broken down into sections, which are usable independently or together.

  1. Python versions

    Installing and managing Python itself.

    • uv python install: Install Python versions.

    • uv python list: View available Python versions.

    • uv python find: Find an installed Python version.

    • uv python uninstall: Uninstall a Python version.

  1. Scripts

    Executing standalone Python scripts, e.g., example.py.

    • uv run: Run a script.

    • uv add --script: Add a dependency to a script

    • uv remove --script: Remove a dependency from a script

  1. Projects

    Creating and working on Python projects, i.e., with a pyproject.toml.

    • uv init: Create a new Python project.

    • uv add: Add a dependency to the project.

    • uv remove: Remove a dependency from the project.

    • uv run: Run a command in the project environment.

    • uv build: Build the project into distribution archives.


Practical use case

One of the most significant shifts uv introduces is the automatic creation of virtual environments . Forget the manual steps of using venv or other tools. uv handles this for you the moment you run your first script in a project.

Let's dive into some practical examples to see uv in action.

Working with Python Projects: Imagine you're starting a new web project. Traditionally, you would do something like this:

python -m venv .venv

source .venv/bin/activate  # On macOS/Linux

.venv\Scripts\activate  # On Windows

pip install <your_dependencies>

Working on Python Projects with

For larger Python projects, uv offers a project structure managed through a pyproject.toml file, which is similar to package.json in JavaScript.

  1. Initializing a Project :

    To start a new project with uv, go to your project directory in the terminal and run:

     uv init <project_name>
    

    For example:

     uv init example-app
    

    The project includes a pyproject.toml, a sample file (main.py), a readme, and a Python version pin file (.python-version).

    The pyproject.toml includes basic metadata. It does not include a build system, it is not a package and will not be installed into the environment:

     # pyproject.toml
     [project]
     name = "example-app"
     version = "0.1.0"
     description = "Add your description here"
     readme = "README.md"
     requires-python = ">=3.13"
     dependencies = []
    

    The sample file defines a main function with some standard boilerplate:

     # main.py
     def main():
         print("Hello from example-app!")
    
     if __name__ == "__main__":
         main()
    

    Python files can be executed with cd example-app <project_name> after run this cmd uv run main.py:

     # output
     Hello from example-app!
    
  2. Adding Dependencies :

    To add dependencies to your project, you can update the dependencies list in the pyproject.toml file. This is similar to adding packages in a package.json file in JavaScript. Once you have added your dependencies, make sure to run the appropriate command to install them in your environment.

    use the uv add command followed by the package names.

     uv add fastapi
    

    This command not only installs the fastapi package and its dependencies but also automatically updates your pyproject.toml file to include fastapi under the [tool.uv.dependencies] section. For example, after adding fastapi, your pyproject.toml might look like this:

     [project]
     name = "example-app"
     version = "0.1.0"
     description = "Add your description here"
     readme = "README.md"
     requires-python = ">=3.13"
     dependencies = [
         "fastapi>=0.115.12", # added fastapi package sucessfully
     ]
    

    A uv.lock file (similar to package-lock.json) is also created to ensure consistent dependency versions across different environments. You generally shouldn't edit this file directly.


Example Code with FastAPI :

from typing import Union

from fastapi import FastAPI
import uvicorn

def main():
    print("Hello from uv-python-no-create-venv!")
    uvicorn.run("main:app", port=5000, log_level="info")

app = FastAPI()

@app.get("/")   
def read_root():    
    return {"Hello": "World"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

if __name__ == "__main__":
    main()

To run this FastAPI application (assuming you have uvicorn installed, which you can add using uv add uvicorn), you can use a command like:

uv run main.py --app main:app --reload

Building a Distributable Package Using uv build

To distribute your project to others (e.g. to upload it to an index like PyPI), you'll need to build it into a distributable format.

Python projects are typically distributed as both source distributions (sdists) and binary distributions (wheels). The former is typically a .tar.gz or .zip file containing the project's source code along with some additional metadata, while the latter is a .whl file containing pre-built artifacts that can be installed directly.

uv build
ls dist/

You can build the project in a different directory by providing a path to uv build, e.g., uv build path/to/project.

uv build will first build a source distribution, and then build a binary distribution (wheel) from that source distribution.


Conclusion

In summary, uv revolutionizes Python project management by automating virtual environments and simplifying dependency handling, making development more efficient and organized.

If you found this blog post helpful, please consider sharing it with others who might benefit. You can also follow me for more content on Python, Fastapi , JavaScript, React.js, Next.js and other web Development and AI topics.

For Paid collaboration, Web Development, AI Agent freelancing work, mail me at: krishdesai044@gmail.com

Connect with me on Twitter, LinkedIn, and GitHub.

Thank you for Reading

Happy Coding

11
Subscribe to my newsletter

Read articles from Krish Desai directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Krish Desai
Krish Desai

I am a Software Engineer. I have 3+ years of experience in building Software Applications with high level production ready code and tech industry.