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

Unlock This Lesson

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

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Python Virtual Environments Recap

Give Feedback

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.

Robert T on March 16, 2019

Good stuff, Dan. I now understand how it works in a Linux OS, it seems so clean compared to Windows with Pycharm. Everything you did was outside of the code editor. I’d really like to see how to accomplish the same thing under Windows and Pycharm.

Douglas Fabretti on April 10, 2019

Nicely explained, short and concise! Thank you very much for sharing this series with us Dan.

Andres Salgado on April 19, 2019

Thank you Dan!! Great course.

Do you care to elaborate on the difference between virtualenv and venv? I understand that based on a stackoverflow entry (stackoverflow.com/questions/41573587/what-is-the-difference-between-venv-pyvenv-pyenv-virtualenv-virtualenvwrappe) virtualenv does not contain all standard libraries. Is that correct?

Dan Bader RP Team on April 19, 2019

@Andres: Thanks! Basically virtualenv and venv do the same thing. You’ll get a fully self-contained Python environment including the full standard library.

The main difference is that venv is included with Python 3 out of the box and not available on Python 2.

So personally I use venv for all Python 3 projects, and I use virtualenv as a fallback for Python 2 projects where venv isn’t available.

Hope that helps you out :)

Anonymous on April 24, 2019

I am working with a Python 2 application and the inconsistency that venv is only available on Python 3 tripped me up. It wasn’t clear to me that venv wasn’t available for Python 2 or why I wasn’t able to install it. I wish that I had seen your most recent comment earlier. Otherwise, the course was direct and clear.

charliem22 on May 28, 2019

Great job! I’m just staring my first ‘big’ project and needed to understand venv machinary. This tutorial was exactly what I needed. Thanks Dan!!! –charlie

Dan Bader RP Team on May 29, 2019

@charliem22: Awesome, glad to hear it!! :)

Koert on June 23, 2019

How difficult can it be to work with virtual environments? Never got it but thanks to your videos I finally understood it! Thanks again.

Abby Jones on June 27, 2019

This is awesome.

DiscreteLoner on Aug. 8, 2019

Easy to follow up.

Rob Black on Aug. 13, 2019

Excellent micro course on virtual environments - exactly the size and pace that I needed. I viewed this course as a side-bar to the tutorial I’m reading now: realpython.com/flask-connexion-rest-api/. Thanks!

UBBA on Aug. 27, 2019

Great video. I am working in VSCode in Windows 10. Couple things I noticed:

  • Which equals where in windows.
  • Did not know that tree worked in windows command prompt
  • VSCode will find your virtual environment and activate it when chosen.
  • You can pip install right from the VSCode terminal for the venv.

Ravi on Dec. 6, 2019

Hi Dan,

In the supporting material, you have mentioned about pyenv, what I understood is we can either use virtualenv or pyenv to maintain dependancies and need not use both of them. Is my understanding correct?

Dan Bader RP Team on Dec. 6, 2019

@Ravi: I actually use a combination of pyenv and venv in my personal workflow.

I use pyenv to install different versions of the Python interpreter on my machine that I might need. So let’s say I have Python 3.7.3 installed, and I also want 3.8.0 for another project. I’ll install these Python versions with pyenv.

And then each individual project still gets a local virtual environment via venv so I can manage installed packages independently.

You can find more info on pyenv in this tutorial: realpython.com/intro-to-pyenv/

Rory on Dec. 11, 2019

Dan, thanks to you and your team for these tutorials. #1 Takeaway? Being able to segregate my code. Still in the learning stage and all my exercise code is in a “Scripts” folder. This will be nice when I start focusing on larger projects. So much to learn! So little time! Thanks again!

Anonymous on March 22, 2020

How do you best deploy a virtual environment from a Linux dev environment to a production server environment? Is there any special set up, or can you just move the entire directory over and it runs without issues?

Dan Bader RP Team on March 22, 2020

Copying the directory over might work if you’re using the exact same operating system and Python setup in your dev environment and on your production server. I wouldn’t recommend it though.

Typically what people do is set up the Python environment + install dependencies from your deploy script, or use something like Docker to build a containerized version of the app that can be used for local testing, staging, and in production.

If you’re using a platform-as-a-service (PaaS) provider like Heroku, they usually come with their own way of configuring the version of the Python interpreter and will install packages from a requirements.txt file upon deploy.

realpython.com is hosted on Heroku and I find that it’s quite a convenient workflow.

Brandon Austin on March 30, 2020

Great and quick to the punch course. Good stuff Dan - really loving the content.

John B on April 16, 2020

Thanks Dan! Concise and clear. Just what I needed.

Alan ODannel on May 6, 2020

I’ve used the Python virtual environments, it’s been a while and I wanted a refresher. This was just what I needed.

James Butler on May 21, 2020

Good tutorial but I encountered a couple of differences between mac and windows 10. First, on windows my command python is 3.7.7 so, I don’t have to use python3. Second, when I executed the command python -m venv ./venv, I get this dir structure; include Lib Scripts No bin dir. I also had to use the git bash terminal in windows 10 because windows does not have terminal commands like source, and which. I was able to activate and deactivate in git bash terminal. Thanks

Ricky White RP Team on May 22, 2020

Hi James. On windows you can activate your venv without using git bash with:

// If using CMD
.\venv\Scripts\activate.bat

// If using Powershell
.\venv\Scripts\Activate.ps1

You can deactivate the environment by just typing deactivate. Hope that helps.

aboahmedah on May 28, 2020

Hi. Great course. How do i setup the standard python IDLE editor to use the interpreter and environment that i need for different projects.

Mark on June 6, 2020

Thanks Dan, Great stuff

stefhx on June 15, 2020

Nice one!

Srini on June 25, 2020

Thanks, Dan. It is a nice session.

koinonia9912 on July 20, 2020

I used ‘where pip3’ on command prompt in Windows 10,as follows: ‘’‘ (base) C:\Users\Craig\Miniconda3\envs>where pip3 C:\Users\Craig\Miniconda3\Scripts\pip3.exe C:\cygwin64\bin\pip3

(base) C:\Users\Craig\Miniconda3\envs> ‘’‘ Which pip3.exe gets used?

Yvonne Wilmot on Sept. 7, 2020

Thanks that was very clear and helpful. Now I need to do this in a Windows environment. Picked up some pointers from the previous comments so those are helpful too.

Become a Member to join the conversation.