VOOZH about

URL: https://thenewstack.io/for-darryl-python-virtual-environment/

⇱ Python virtual environments: isolation without the chaos - 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
2026-02-16 07:00:17
Python virtual environments: isolation without the chaos
tutorial,
Containers / Python / Software Development

Python virtual environments: isolation without the chaos

Virtual environments isolate Python dependencies at the project level, preventing version conflicts and keeping experiments contained without affecting system-wide installations.
Feb 16th, 2026 7:00am by Jessica Wachtel
👁 Featued image for: Python virtual environments: isolation without the chaos
Featured image by Galina Nelyubova for Unsplash+.

Installing packages globally isn’t always a good idea. Different tools inside an application can require specific versions of features, functions, or dependencies. These can conflict with or break other parts of the same application or other projects on your system. There’s a simple solution. Install locally not globally. Favoring more local installations isn’t a new idea in software development. One of the core principles of development is to use lightweight, isolated setups, and modular code. This keeps code contained, modular, and predictable.

These same ideas helped drive the rise of container-based development (think Docker). Containers isolate applications and their dependencies so they can run reliably in different environments. Virtual environments apply that same principle at the language level. They let you isolate dependencies for a specific project, no matter how big or small, without affecting anything else on your system.

What is a virtual machine?

A virtual machine, aka virtual environment, is an isolated installation that lives directly in your project directory. Think of it as a self-contained workspace for a single project.

In Python, each virtual environment includes its own Python interpreter, package installer (pip), and installed libraries. These aren’t unique to virtual environments, these elements are included in every Python project. The difference with projects built with virtual environments is that everything is isolated. Each environment has its own copies of the Python interpreter, `pip`, and libraries, so changes in one project won’t affect any other project or the system Python.

Global installs aren’t always problem but they can be. For example:

  • Project A needs requests version 2.25
  • Project B needs requests version 2.31

Globally, only one version of a package is active at a time. With virtual environments, however, each project can have its own version, allowing both projects to work independently. This isolation makes applications easier to maintain. For example, a new version might break Project A but is necessary for Project B. It also makes projects more reliable and safer to experiment with.

Virtual environments are easy to work with. The remainder of this tutorial will build two Python virtual environments inside the same project to show how each can have its own packages and produce different results from the same Python script.

Virtual environments aren’t unique to Python but this tutorial will use the Python language. Please make sure you have Python installed on your machine before starting.

Building Python virtual environments

Open a new project in your IDE and let’s set up our folders:

Once you’re in the new folder, we’re ready to build the virtual environments. We’re going to build two virtual environments.

Upon successful completion, you’ll see a new folder called venvwith a new folder/ file tree under it. You should see a venv_old and venv_new.

Activate Python virtual environment

We’re going to work onvenv_old first. Use the following command in your terminal. Don’t cd into the venv folder. Run the following command while in the parent folder,build_venv.

You will then see a (venv) before your command prompt in your terminal.

Install packages in Python virtual environment

Now we’re ready to installnumpy intovenv_old. This process looks similar to installing globally but it will only install numpy in the virtual environment.

Run Python inside the virtual environment

Next, we’re going to create our main.py file. The code inmain.py will not run if numpy isn’t installed (more on that later).

Create the file.

Oncemain.py appears in your folder tree, add this code to the file.

Once added, run the following code in your terminal. Quick note, the command in my terminal for running Python scripts ispython3. Yours might bepython or something else entirely. You can check by running python --version or python3 --versionand keep troubleshooting.

Upon successful completion you’ll see  a random number in the terminal.

Deactivating Python virtual environment

Before we can test main.py in venv_new, we’ll need to deactivatevenv_old You can do that by typing the following into your terminal.

Working in the second virtual environment

Now, let’s activatevenv_new.

Run main.py.

You should see an error becausenumpyisn’t installed invenv_new.

If you then deactivate venv_newand runmain.pywith neither virtual environment, you will see a random number. This is because Python uses the system or user-installed packages, so your script can still find NumPy and run successfully. Virtual environments only isolate packages inside that environment, so without one, Python falls back to whatever is installed globally or for your user.

Working with virtual environments

This simple setup shows how virtual environments let you control exactly which packages each project uses, preventing conflicts and making experiments safe. Even in a small project, isolating dependencies can save a lot of headaches down the line.

TRENDING STORIES
Jessica Wachtel is a developer marketing writer at InfluxData where she creates content that helps make the world of time series data more understandable and accessible. Jessica has a background in software development and technical journalism.
Read more from Jessica Wachtel
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker.
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.