Skip to content

Python Virtual Environments

It’s common to have multiple Python applications running on your system.

When applications require the same module, at some point you will reach a tricky situation where an app needs a version of a module, and another app a different version of that same module.

To solve this, you use virtual environments.

We’ll use venv. Other tools work similarly, like pipenv.

Create a virtual environment using

python -m venv .venv

in the folder where you want to start the project, or where you already have an existing project.

Then run

source .venv/bin/activate

Use source .venv/bin/activate.fish on the Fish shell

Executing the program will activate the Python virtual environment. Depending on your configuration you might also see your terminal prompt change.

Mine changed from

➜ folder

to

(.venv) ➜ folder

Now running pip will use this virtual environment instead of the global environment.


→ Get my Python Handbook
→ Get my Python Handbook

→ I wrote 17 books to help you become a better developer:

  • C Handbook
  • Command Line Handbook
  • CSS Handbook
  • Express Handbook
  • Git Cheat Sheet
  • Go Handbook
  • HTML Handbook
  • JS Handbook
  • Laravel Handbook
  • Next.js Handbook
  • Node.js Handbook
  • PHP Handbook
  • Python Handbook
  • React Handbook
  • SQL Handbook
  • Svelte Handbook
  • Swift Handbook
...download them all now!

Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list