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:05 So, how about we tell pip to temporary install packages in a different folder, and then we tell our Python interpreter to use that folder instead?
0:13 Well, that's exactly what virtual environment does. A virtual environment is a special folder that contains a Python,
0:20 binary and any additional packages that you install. When you activate a virtual environment,
0:27 two things happen. First, you tell pip to install any new packages to that
0:32 folder, and then you tell Python interpreter to use packages from that folder.
0:38 Let's see an example. so, when we are not using a virtual environment and we tell pip to install Django 3,
0:44 it's going to install it in the global site packages. And then, when we tell pip to install Django 2,
0:50 is going to install the previous version of Django and install the new one,
0:54 as we already saw. If we use the virtual environment, first we activate a specific folder that we want to use. Then we tell pip to install Django 3,
1:04 and as you can see, it's going to be installed not in a global site Packages but in side this Django 3 application,
1:11 and then we tell virtual environment to activate a different environment. And when we tell pip to install Django 2.2 this time,
1:18 it's not going to uninstall anything because it's going to use site packages from a different folder
25:02 then previously.


Talk Python's Mastodon Michael Kennedy's Mastodon