Virtual Environments and pip for Data Projects
SkillVeris Team
Engineering Team

You will understand why isolated environments prevent dependency conflicts between projects.
In this guide, you'll learn:
- You will create and activate a virtual environment with Python's built-in venv.
- You will install, upgrade, and remove packages confidently with pip.
- You will pin dependencies in a requirements file for fully reproducible setups.
- You will know when to reach for conda instead of pip and venv.
1Why Virtual Environments Matter
A virtual environment is an isolated Python setup for a single project, with its own installed packages that cannot clash with other projects. Combined with pip, Python's package installer, it gives every data project a clean, reproducible foundation and ends the dependency conflicts that plague beginners.
The problem it solves is concrete. Project A needs pandas version 1.5, Project B needs 2.1, and if you install packages globally, upgrading for one breaks the other. Virtual environments give each project its own sealed box of dependencies, so they never interfere.
This is also the cure for the infamous it works on my machine problem. When you record exactly which packages and versions a project needs, anyone can recreate the same environment and get the same results.
2The Dependency Problem in Detail
Without isolation, every pip install adds to one shared global set of packages. Over months this becomes a tangled pile where upgrading a library for a new project silently breaks an old one, and no single set of versions satisfies everything. Data work makes this worse because libraries like pandas, NumPy, and scikit-learn evolve quickly and depend on each other.
Virtual environments cut the knot by giving each project a private folder of packages. Activating an environment tells Python to look there instead of globally, so what you install for one project is invisible to the rest. The global installation stays clean, and each project controls its own fate.
🔑One environment per project
The simple rule that avoids nearly all dependency pain: create a fresh virtual environment for every project, and never install project packages globally.
3Creating an Environment With venv
Python ships with a built-in tool called venv, so there is nothing extra to install. Inside your project folder, run python -m venv .venv to create an environment in a hidden .venv folder. That folder now holds a private copy of Python and a place for this project's packages.
Next you activate it, which differs by operating system. On macOS or Linux run source .venv/bin/activate; on Windows run .venv\Scripts\activate. Your terminal prompt changes to show the environment name, confirming it is active. Anything you install now goes into this project alone. When finished, type deactivate to leave.
- python -m venv .venv creates the environment.
- source .venv/bin/activate activates it on macOS and Linux.
- .venv\Scripts\activate activates it on Windows.
- The changed prompt confirms the environment is active.
- deactivate returns you to the global Python.
4Managing Packages With pip
With an environment active, pip installs packages into it. Install one with pip install pandas, a specific version with pip install pandas==2.1.0, or several at once by listing them. Upgrade with pip install --upgrade pandas and remove with pip uninstall pandas. See what is installed with pip list.
Because the environment is isolated, you can install and experiment freely without fear of harming other projects or your system Python. If an environment ever gets into a bad state, the nuclear option is easy: delete the .venv folder and recreate it from your requirements file.
💡Upgrade pip first
Right after creating an environment, run python -m pip install --upgrade pip. A current pip avoids many confusing installation errors, especially with data libraries that ship compiled components.
5Reproducibility With requirements.txt
The step that turns a working environment into a shareable one is pinning your dependencies. Run pip freeze > requirements.txt to write every installed package and its exact version to a file. Commit that file with your project, and anyone can recreate your environment with pip install -r requirements.txt.
This file is the contract that makes analysis reproducible. Six months from now, or on a colleague's laptop, the same versions install and the same code behaves the same way. Regenerate the file whenever you add or upgrade a package, so it always reflects reality.
Pinning versus loose versions
pip freeze pins exact versions, which is the safest choice for reproducibility. Some teams instead keep a loosely versioned file of top-level packages and let a tool resolve the rest. For most data analysts, pinning exact versions is the simplest path to results that do not drift over time.
6When to Use conda Instead
pip and venv are the standard, lightweight choice, but conda is a popular alternative in data science, bundled with the Anaconda and Miniconda distributions. conda manages both Python packages and non-Python dependencies like compilers and system libraries, which some scientific packages need.
conda creates environments with conda create -n myproject python=3.11 and installs with conda install. Its advantage is smoother handling of hard-to-build packages; its cost is a larger footprint and a separate ecosystem. A reasonable rule is to use pip and venv by default and switch to conda only if you hit installation trouble with heavy scientific libraries.
7A Clean Per-Project Workflow
Putting it together, every new data project can follow the same short ritual, and doing it by reflex saves endless trouble later.
- Create the project folder and move into it.
- Create and activate a virtual environment with venv.
- Upgrade pip, then install the packages you need.
- Write a requirements.txt with pip freeze once things work.
- Add .venv to .gitignore so the environment is never committed.
- Commit requirements.txt so others can rebuild the environment.
8Common Mistakes to Avoid
A few recurring errors cause most of the confusion beginners have with environments, and knowing them turns baffling problems into obvious fixes.
- Forgetting to activate the environment, so packages install globally instead.
- Committing the whole .venv folder rather than just requirements.txt.
- Never regenerating requirements.txt after adding packages, so it goes stale.
- Mixing conda and pip carelessly in one environment, which can corrupt it.
- Installing everything globally out of habit and rediscovering conflicts later.
9Frequently Asked Questions
What is the difference between pip and a virtual environment? pip is the tool that installs Python packages, while a virtual environment is an isolated space for those packages to live. You use pip inside a virtual environment so each project has its own private set of dependencies.
Do I really need a virtual environment for small projects? It is a good habit even for small work, because projects grow and dependencies accumulate. The cost is two commands, and the payoff is never having one project's packages break another. Get in the habit early.
What does requirements.txt do? It lists every package and version your project needs, produced with pip freeze. Anyone can then recreate your exact environment by running pip install -r requirements.txt, which makes your analysis reproducible on other machines and in the future.
Should I use venv or conda? Use pip and the built-in venv by default, since they are standard and lightweight. Switch to conda if you struggle to install heavy scientific packages with compiled components, as conda manages those non-Python dependencies more smoothly.
Should I commit my virtual environment folder to Git? No. The .venv folder is large and machine-specific, so add it to .gitignore. Commit requirements.txt instead, which lets anyone rebuild the same environment without carrying thousands of files.
Why do my packages install globally even inside a project? Almost always because the environment is not activated. Check that your prompt shows the environment name, and if not, run the activate command again before installing anything.
10Next Steps
Virtual environments and pip are the quiet foundation of every reliable data project. Isolate each project, install its packages privately, pin them in a requirements file, and you eliminate dependency conflicts and the it-works-on-my-machine problem in one stroke. It is a small ritual with an outsized payoff in sanity.
You can learn this alongside Python, pandas, and the wider data workflow for free on SkillVeris, where the courses and study notes cover environment setup as part of building real projects. Set up a clean environment for your next analysis, and every project after it will start on solid ground.
Get The Print Version
Download a PDF of this article for offline reading.
About the Publisher
SkillVeris Team
Engineering Team
Our engineering writers turn abstract code concepts into hands-on, project-driven learning experiences.
View all postsRelated Posts
Never miss an update
Get the latest tutorials and guides delivered to your inbox.
No spam. Unsubscribe anytime.