Modern Python Projects Transcripts
Chapter: Python versions and packages
Lecture: What are virtual environments?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The problem with pip is that it installs all the packages in the same folder.
0:04 So, how about we tell pip to temporary install packages in a different folder,
0:08 and then we tell our Python interpreter to use that folder instead?
0:12 Well, that's exactly what virtual environment does.
0:15 A virtual environment is a special folder that contains a python,
0:19 binary and any additional packages that you install.
0:23 When you activate a virtual environment,
0:26 two things happen. First, you tell pip to install any new packages to that
0:31 folder, and then you tell Python interpreter to use packages from that folder.
0:37 Let's see an example. so, when we are not using a virtual environment and we
0:41 tell pip to install Django 3,
0:43 it's going to install it in the global site packages.
0:47 And then, when we tell pip to install Django 2,
0:49 is going to install the previous version of Django and install the new one,
0:53 as we already saw. If we use the virtual environment, first we activate a specific
0:58 folder that we want to use.
1:00 Then we tell pip to install Django 3,
1:03 and as you can see, it's going to be installed not in a global site
1:06 Packages but in side this Django 3 application,
1:10 and then we tell virtual environment to activate a different environment.
1:14 And when we tell pip to install Django 2.2 this time,
1:17 it's not going to uninstall anything because it's going to use site packages from a different folder
25:01 then previously.