Skip to content

How to Create and Activate a Virtual Environment πŸ• ​

Now that we’ve established virtual environments are like personal pan pizzas (no one touches your toppings!), let’s actually cook one up. πŸ•πŸ”₯

πŸ§ͺ Step 1: Check if You Have venv Installed ​

You probably do! Python 3.3+ comes with it baked in like extra cheese.

Just to be sure, run this in your terminal:

bash
python3 -m venv --help

If you see a bunch of options instead of errors β€” congrats, you’re all set!

πŸ—οΈ Step 2: Create a Virtual Environment ​

Pick a name for your environment. People usually go with:

  • venv
  • .venv
  • env
  • my-cute-python-bubble

Let’s roll with venv for now:

bash
python3 -m venv venv

This will create a new folder called venv with all your Python goodness neatly packed inside.

⚑ Step 3: Activate the Environment ​

Here’s where it gets OS-specific. Don’t worry, it's like choosing your starter PokΓ©mon.

πŸͺŸ Windows ​

bash
venv\Scripts\activate

If it works, your terminal will suddenly have (venv) in front of the prompt like this:

(venv) C:\User\YourComputer>

This means you are now inside your own little Python universe. Welcome, astronaut. πŸ§‘β€πŸš€

🐧 Linux / 🍎 macOS ​

bash
source venv/bin/activate

And again, you’ll see (venv) in your terminal. Boom. You're now operating in a bubble that’s isolated, fresh, and drama-free.

🧠 Bonus: Confirm You’re Using the Right Python ​

After activating, run:

bash
which python
# or
where python

You should see the path pointing to something like venv/bin/python. That means everything β€” including pip install β€” stays inside your pizza box. πŸ•

πŸ’‘ Pro Tip ​

You can make a requirements.txt file (remember that thing?) and install everything like this:

bash
pip install -r requirements.txt

Just don't forget: Activate before you pip, or else your laptop might start sprinkling packages all over your system like parmesan cheese in a windstorm.

Built by noobs, for noobs, with love πŸ’»β€οΈ