VOOZH about

URL: https://thenewstack.io/why-every-python-dev-needs-virtual-environments-now/

⇱ Why Every Python Dev Needs Virtual Environments Now - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2025-01-09 07:30:23
Why Every Python Dev Needs Virtual Environments Now
Programming Languages / Python / Software Development

Why Every Python Dev Needs Virtual Environments Now

A virtual environment is an isolated sandbox that allows you to install everything you need for a project without affecting things globally. Python contains everything you need to create and use a virtual environment, and it's easy.
Jan 9th, 2025 7:30am by Jack Wallen
👁 Featued image for: Why Every Python Dev Needs Virtual Environments Now
Featured image via Unsplash.
When developing with Python, chances are pretty good that you’ll need to install various libraries, dependencies and apps to get your project started. The good news is that (in most cases) those installations are pretty straightforward (thanks to pip and other tools). Problems can arise, however, if you simply install all of those project requirements on your system. It’s like installing any given application, hoping it won’t cause problems with other applications, your OS or your data. In most cases, it’s safe, but there’s always that one instance where things can quickly go awry. You do not want this. After all, your system is where you do your work, and your work is your livelihood. With that in mind, why would you want to risk even the slightest issue that could set you and your project back? This is especially so when you’re on a tight deadline and have to deliver on time or risk losing a client (or your job). To that end, what do you do? You use virtual environments.

What Are Virtual Environments?

A virtual environment is an isolated sandbox that allows you to install everything you need for a project without affecting things globally. Within a virtual environment, you can install all of the libraries and dependencies you need without touching the global Python installation. Think of Python Virtual Environments like a virtual machine. If you’ve ever used a tool like VirtualBox, you know that host and guest do not affect one another, and anything you do to a guest OS will have no bearing on the host OS. You could effectively install a Linux guest OS, log in, run the sudo rm -rf / command (don’t do that) and it would destroy the guest OS but not touch the host. Python Virtual Environments work in a similar fashion and offer the following benefits:
  • They allow you to work on multiple projects with different dependencies at the same time.
  • They allow you to create portable projects.
  • There’s no risk of version conflicts.
  • They avoid the need for global package installation.
  • They make it easier for testing.
  • They make clean up easier.
  • They simplify collaboration.
  • They are more easily reproducible.
  • They offer dependency isolation. 
  • They create a much cleaner and organized workspace.
Ask any seasoned Python developer and they’ll tell you that every project you create should be done in a virtual environment. The good news is that Python contains everything you need to create and use a virtual environment. Even better, creating a virtual environment is very easy.  Let me show you how to create, activate, deactivate and delete a Python virtual environment.

What You’ll Need

The only thing you’ll need for this is to install Python on your OS of choice. I’ll demonstrate this on Pop!_OS Linux with Python version 3.10.12, but the process is the same, regardless of the operating system. Do note that as long as you’re using Python version 3.4 and up, it has everything you need to do this. If you’re using a version of Python older than 3.4, I suggest you upgrade; otherwise, you’ll need to install virtualenv using Pip (pip install virtualenv).

Creating a Virtual Environment

The first thing you want to do is create a new virtual environment.  Log in to your OS and open a terminal window. Once you have access to the CLI, create a directory to house your Python projects like so:
mkdir PYTHON
Change into that parent directory with the command:
cd PYTHON
Let’s say you’re about to embark on developing a project named ProjectX. Create a new virtual environment for that project with the command:
python -m venv ProjectX
If you receive an error, you might have to install the required venv command for your version of Python, like so:
sudo apt-get instll python3.10-venv
If you’re using a version of Python older than 3.4, the command would be:
virtualenv ProjectX
You should now find a new directory called ProjectX. Inside that directory, you’ll find the following sub-directories:
  • bin
  • include
  • lib
  • lib64
You should also find a file named pyvenv.cfg. Change into the ProjectX directory with the command:
cd ProjectX
Next, you need to activate the project with the command:
source bin/activate
You should see your prompt change. It will now look something like this:
(ProjectX) hostname ->
If you’re on a Windows environment, the activation will be one of the following:
  • For cmd.exe – venv\Scripts\activate.bat
  • For PowerShell – venv\Scripts\Activate.ps1
At this point, you can install all of the necessary libraries and dependencies required for the project without affecting your system. Once you have your dependencies installed, you can start working on your project.

Deactivating a Project

When you’re finished working on a project, it’s good practice to deactivate it. This will leave the virtual environment intact but prevent anything from happening to it.  To deactivate a virtual environment, type the following command within the project directory:
deactivate
Any time you need, you can change back into that directory and run the activate command as you did earlier.

Deleting a Virtual Environment

If you need to delete that virtual environment, all you have to do is deactivate it and then delete the directory with the following commands: If you’re working on a Windows environment, you’ll need to change the last two commands to use the Windows equivalent. And that, my friends, is all there is to working with a Python virtual environment.
TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.