DEV Community

Cover image for Python Virtual Environments: Why You Need Them and How to Use Them
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on • Edited on

Python Virtual Environments: Why You Need Them and How to Use Them

Hello, I'm Maneshwar. I'm building git-lrc, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. Star Us to help devs discover the project. Do give it a try and share your feedback for improving the product.

Hello, I'm Maneshwar. I'm working on FreeDevTools online currently building **one place for all dev tools, cheat codes, and TLDRs* — a free, open-source hub where developers can quickly find and use tools without any hassle of searching all over the internet.

If you’re diving into Python development, chances are you’ve heard whispers of something called "virtual environments" or simply "venv."

At first, it might sound a bit mysterious, but trust me, this little tool can become your best friend.

Let’s break it all down and see why it’s essential, how to use it, and the possibilities it unlocks.

What Is a Virtual Environment (venv)?

A virtua
l environment is like your personal workspace for a Python project. It’s an isolated environment where you can:

  • Install project-specific packages without messing up your global Python installation.
  • Use different versions of the same package across projects (because compatibility issues are a developer’s nightmare).
  • Keep your project dependencies clean and organized.

Imagine you’re working on two Python projects:

  1. Project A needs Django 4.0.
  2. Project B needs Django 3.2.

Without virtual environments, installing both versions on the same machine would result in chaos.

With virtual environments, you can switch between them seamlessly!


source

How to Set Up and Activate venv in Linux

Ready to set up your first virtual environment? Follow these steps:

1. Install venv

Most Python installations include venv, but if not, install it using:

sudo apt install python3-venv
Enter fullscreen mode Exit fullscreen mode

2. Create a Virtual Environment

Go to your project directory and create a virtual environment:

python3 -m venv venve
Enter fullscreen mode Exit fullscreen mode

Here, venv is the name of your virtual environment.

You can call it whatever you like.

3. Activate the Virtual Environment

To start using the virtual environment, activate it:

source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

You’ll know it’s activated because your terminal prompt will change to something like:

(venv) lovestaco@i3nux-mint:~$
Enter fullscreen mode Exit fullscreen mode

4. Install Deps

Now you can install packages specific to your project:

pip install flask
Enter fullscreen mode Exit fullscreen mode

6. Deactivate the Environment

When you’re done, deactivate the environment:

deactivate
Enter fullscreen mode Exit fullscreen mode

And you’re back to your system Python!

What Can You Do with venv?

The possibilities are endless! Here are a few ideas:

  • Experiment with Libraries: Try out new libraries or frameworks without worrying about breaking your system setup.
  • Version Testing: Test your code with different versions of Python or dependencies.
  • Collaborate Easily: Share a requirements.txt file with your team so everyone can set up the same environment.
  pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

Your teammates can recreate the environment with:

  pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode
  • Deploy Projects: Virtual environments make it easy to deploy your projects to servers or containers.

Wrapping Up

Virtual environments are a simple yet powerful tool that every Python developer should use.

With just a few commands, you can create, activate, and manage isolated Python environments tailored to your projects.

So the next time you start a Python project, remember to fire up a virtual environment.

I’ve been building A collection of UI/UX-focused tools crafted to simplify workflows, save time, and reduce friction in searching tools/materials.

Any feedback or contributors are welcome!

It’s online, open-source, and ready for anyone to use.

👉 Check it out: FreeDevTools
⭐ Star it on GitHub: freedevtools

Let’s make it even better together.

git-lrc
*AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.*

Any feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.

⭐ Star it on GitHub:

GitHub logo HexmosTech / git-lrc

Free, Unlimited AI Code Reviews That Run on Commit

git-lrc logo

git-lrc

Free, Unlimited AI Code Reviews That Run on Commit


git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.

See It In Action

See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements

git-lrc-intro-60s.mp4

Why

  • 🤖 AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
  • 🔍 Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
  • 🔁 Build a habit, ship better code. Regular review → fewer bugs → more robust code → better results in your team.
  • 🔗 Why git? Git is universal. Every editor, every IDE, every AI…




Top comments (1)

Collapse
 
georgios_athanasopoulos_f profile image
georgios athanasopoulos

Intresting Topic, do you have an explanation about why would anyone use venv's for autotomation tools??