← Back to Articles

Python Virtual Environments

Why do you need a virtual environment for python?

A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages. It allows you to manage dependencies for different projects separately, avoiding conflicts between them. This is especially important when working on multiple projects that may require different versions of the same package.

Why You Need It

How It Works

If you install a dependency with uv do you still need to check that you are in the project 's environment?

One of the nice things about uv is that it automatically finds and uses the project's virtual environment, so you don't need to manually activate it first like you often would with venv + pip.

uv add[package-name]

If you don't use uv, how do you manage virtual environments?

what does pip3 install do in terms of virtual environment?

Pip3 install does not directly install the package inside a virtual environment. Instead, it installs the package into the global site-packages directory on your Mac. This means that if you have multiple versions of Python installed on your Mac, pip3 will install the package in the version that is currently active.

When you run pip3 install, its behavior depends entirely on whether your virtual environment is active or inactive in your terminal.

If the Environment is Active (Turned On)

If the environment is active, pip3 will install the package into the virtual environment's private folder. This means that the package will only be available in the project you are currently working on.

pip3 install [package-name] Installs inside the virtual environment: The package goes into your virtual environment's private folder.

If the Environment is Inactive (Turned Off)

If the environment is inactive, pip3 install [package-name] will install the package into your Mac's global Python installation. This means that the package will be available to all projects on your computer, but it may also cause conflicts with other packages or versions.

How to Check Before Installing

Before you run pip3 install, look at your terminal prompt. If a virtual environment is active, you will see its name in parentheses at the very beginning of the line:

You can also run which pip3. If it points to your project folder, it is safe to install. If it points to /usr/local/bin/ or /opt/homebrew/, it will install globally.