Creating a Virtual Environment

This lesson covers how to create a virtual environment in a project folder. You learned that following the steps below will install a self contained Python environment in your project directory:

  • Create a project directory
  • Change into the project directory
  • Run python3 -m venv <name_of_virtualenv>

Comments & Discussion

Andreas Schipplock on April 7, 2019

Hi, is this still considered a best-practice to create the venv inside the project? I somewhere read it’s advised to create all of your venvs inside ~ (or $HOME).

I’m just curious :).

Thanks in advance.

Regards, Andreas

Dan Bader RP Team on April 8, 2019

@Andreas: I still create all of my venvs that way, I think it’s more of a “philosophical” point as to which practice is better (venv in project folder vs venv in global folder like ~/venvs).

What I would avoid is having shared global venvs that are used by multiple projects. It might make sense under some circumstances, like when you have several scripts/apps that all use the same set of dependencies.

But over time and as these projects evolve it can become a hassle to keep the shared venv clean. I find per-project venvs much easier to manage over the long term.

Hope this helps you out!

Become a Member to join the conversation.