How to activate a virtual Python environment

3 quick steps to simplify Python package installation
Tutorials
Author

Vivek Sriram

Published

May 15, 2025

Modified

May 15, 2025

Welcome back to my personal biomedical data science blog, [VS]Codes! Today’s blog post will be a brief tutorial on how to create and activate a virtual environment for your Python project.

I’ve recently been working on a lot of code with older Python packages that are not supported for the most recent versions of Python. So, I’ve needed to find a way to make use of an alternate version of Python for my project. The solution? Setting up a Python virtual environment.

The following StackOverflow post provides a great overview of the benefits of Python virtual environments. Here’s a brief summary of its key takeaways:

Now let’s go into the steps for setting up a Python virtual environment.

Note

These next steps assumes that you are working on a Mac. Our example will focus on setting up a Python 3.10 virtual environment. Refer to the StackOverflow post above for instructions for Windows systems.

Step 1: Install the version of Python that you need

First, install Python 3.10 if you don’t already have it. If you’re on macOS, you can use Homebrew to install Python 3.10 from your Terminal:

brew install python@3.10

Then, verify your installation:

python3.10 --version

Step 2: Create a Virtual Environment

Now, we can create a new virtual environment for our project using Python 3.10:

Navigate to your project folder in your Terminal:

cd path/to/your/project

Create a virtual environment using the following command:

python3.10 -m venv [environment_name]

For instance, if we wanted to name our environment .breaking_bad, our command would be:

python3.10 -m venv .breaking_bad
Tip

It is good practice to start the name of your virtual environment with a period (.) so that the folder becomes hidden by default on your system - in the process, you can keep your project directory clean, help prevent accidental Git commits, and more easily avoid potential namespace conflicts.

Finally, we can active the virtual environment we’ve just created!

source .breaking_bad/bin/activate

After activation, our terminal prompt should show the name of our environment (e.g. (.breaking_bad)$).

Step 3: Install your required Python packages

Once inside your virtual environment, you can install any Python packages that you want! For instance:

(.breaking_bad)$ pip install medspacy

And ta-da! Mission accomplished!

References