Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Python Virtual Environments Recap

This lesson is a recap of the entire course, it covers the benefits of using virtual environments and best practices to follow when using them in your projects.

Take the Quiz: Test your knowledge with our interactive “Python Virtual Environments: A Primer” quiz. You’ll receive a score upon completion to help you track your learning progress:


Interactive Quiz

Python Virtual Environments: A Primer

In this quiz, you'll test your understanding of Python virtual environments. With this knowledge, you'll be able to avoid dependency conflicts and help other developers reproduce your development environment.

Avatar image for Jesus Espinoza

Jesus Espinoza on July 5, 2021

Great tutorial!! Thanks for sharing!!

Avatar image for Philip GeLinas

Philip GeLinas on Sept. 25, 2021

Short, sweet, to the point. Excellent!

Avatar image for aniketbarphe

aniketbarphe on Nov. 25, 2021

Excellent Session! Thank You!

Avatar image for mwolf

mwolf on Jan. 9, 2022

Thank you very much! Very well explained and presented!

Avatar image for L Kenneth Wells

L Kenneth Wells on Dec. 27, 2022

I’ve always wanted t understand this and now its super simple. Thank you. Also I was wondering should I learn Linux if I run everything on Windows? Just curious and thank you!

Avatar image for atenn99

atenn99 on Jan. 2, 2023

Just rejoined RealPython and this has been super helpful in making me realise what venvs are & why they are super important. Excellent tutorial. Off to create my new venv!

Avatar image for Danadasa Chan

Danadasa Chan on July 26, 2023

Hi Dan. Thanks for this very informative and easy to understand tutorial. When I attempted to activate my virtual environment, I got an error message that said I could not run a batch file because execution policy default setting is Restricted. To fix this, I opened a powershell prompt with administrative privileges and I set execution policy to RemoteSigned. And how the batch file executes and everything works just fine. I am wondering if I should change execution policy back to Restricted after I am done coding, or can I leave as RemotedSigned.

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Aug. 7, 2023

@Danadasa Chan If you’re going to be working in virtual environments frequently, then it’s probably more convenient to leave the execution policy as it. I’m not a Windows expert myself, but I think that you should be able to narrow down the scope of this policy to only apply to a particular user account or script. Maybe you can find more details in our Windows Setup Guide?

Avatar image for SirVeyor

SirVeyor on April 6, 2024

What are the best practices for venv? Should you create virtual environments for each project? Can you use the same venv for multiple projects that are using the same python version?

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on April 8, 2024

@SirVeyor It’s considered the best practice to create a separate virtual environment for each of your projects so that their dependencies remain isolated from each other. Technically, you can reuse the same virtual environment for multiple projects by activating it before running the corresponding source code. That may sometimes make sense, but in general, you want to have a virtual environment per project, which is why you often keep it in a local .venv/ folder inside of your project.

(By the way, a virtual environment is a lightweight copy of a particular Python interpreter, which means that it’s tied to that specific Python version.)

Become a Member to join the conversation.