The Simplest Way to Create a Python Virtual Environment

Mar 09, 2020 · Updated: Jul 12, 2021 · by Tim Kamanin

A lot of fog and mysteries surround Python virtual environments. There are loads of packages, tools, and wrappers trying to make developer's life with virtual environments easier.

But if we look at the basics, we'll see that actually, creating a virtual environment in Python has never been easier.

Starting from Python 3.3, you can create a virtual environment by simply running the following command in a terminal:

python -m venv myblog

That's all! You've just created a Python virtual environment!

Behind the scenes, the command has created the myblog virtual environment and the directory with the same name at your current location.

Now you can activate myblog environment by running:

source myblog/bin/activate

When a virtual environment is activated, any command you run in the current terminal session will use Python executable and packages installed under the myblog environment.

So if you run a pip install command like this:

pip install Django

It will install Django into the myblog virtual environment. Neat, huh?

How to deactivate a virtual environment?

If you want to leave the previously activated environment, run the following command in a terminal:


Alternatively, you could close the terminal window and achieve the same effect.

Now you know that Python virtual environment isn't a mystery anymore. So go and create one!

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓