Modern Python Projects Transcripts
Chapter: Python versions and packages
Lecture: Typical workflow with virtual environment
0:00 Let's see how we would use virtual environments in our daily work.
0:04 Typically, you would create one virtual environment for each of your projects.
0:08 So let's come back to my example with two projects using different Django versions,
0:13 I have created two folders one called my_django_app and second one called client_django_app.
0:18 We will go inside both folders and create a virtual environment there.
0:26 Here is a quick tip. I told you that it's a common practice to name
0:30 virtual environment folder venv or .venv that way your code editor will automatically detected.
0:37 But also you will immediately see that this folder contains stuff related to the virtual environment
0:42 But if you have many projects and you switch between them,
0:46 it can be very confusing toe always see venv,
0:49 as the name of the virtual environment. You might install,
0:52 the wrong packages in the wrong environment by mistake,
0:55 So, to make it easier to immediately tell which environment is active.
0:59 You can pass the --prompt parameter.
1:02 This will change the name of the virtual environment without changing the folders name.
1:07 So, as you can see, we have a folder with the virtual environment called .venv
1:11 But when we activated, the name of the virtual environment is actually mydjango3app
1:17 So, let's go and create a virtual environment for the other folder as
1:22 well. All right, we're all set.
1:33 We have two projects. Each of them has its own virtual environment.
1:37 Now let's say I want to work on this Django 2 application for my client.
1:41 I go inside the Projects folder and I activate the virtual environment.
1:45 I do some coding. Maybe I installed some packages and stuff like that. At the
1:49 end of the day. Maybe I want to work on my personal Django project.
1:53 So I deactivate this one, and I switched to the other folder and I activate
1:58 the other virtual environment. Again, I do some coding here.
2:03 I installed some other packages, and then the next day, I switch back to my
2:09 client's application. And if I forget to run the activate,
2:13 that's fine. When I activate another environment while the previous one is still active,
2:18 the preface one is automatically deactivated first,
2:20 So, when you are switching from one virtual environment to another,you can skip this deactivate command