Copy the Requirements File
00:00 Let me show you the third solution, how to install the packages with one command. For this, I cleared the terminal and I deactivated any virtual environments.
00:10
I am still in my other exercises folder. And there we have the two virtual environments as folders in there. So with ls
, I can check that we could create a third virtual environment.
00:23 We could also work with existing virtual environments. But I also want to show you that there is actually no harm in throwing away virtual environments if you do not need them anymore.
00:34 Be careful with this because if you have not frozen your packages in a requirements file, then it is hard to recreate your development environment. But here we have a different environment that we want to copy.
00:47 So here there is no harm in removing those two folders. Now, removing is a harsh action. So you can do this in a terminal if you feel safe, but it is also no harm if you are working in the terminal to sometimes step into the file explorer to, for example, delete things or copy things, which I will show you in a moment.
01:10 So just because you are going to use a terminal for certain things does not mean you need to. You must use it for all the things. So if you are not feeling comfortable with certain things, it is totally okay to step out of it.
01:22
And that is what I will do here now. So in the file explorer, I will select venv2
and venv
inside my other exercises folder and then move them to the bin, which basically means deleting them to continue.
01:40
Now I want to create a new virtual environment inside of other exercises. So I use python3 -m venv
, and since the other venv
folder is not there anymore, I can reuse the venv
name.
01:55
And then I have a fresh virtual environment, which I can activate with source venv/bin/
02:03
activate
, and verify that there are really no other packages besides the standard packages installed with Python
02:19 Perfect. Okay, so another variant of installing the packages from the other virtual environment is by just copying your requirements file into your current directory.
02:35 And again, here I am using the file explorer for this because why not? I’m pressing the alt key on the Mac and then dragging it to my other exercises folder.
02:47
And if I go back to the terminal and use ls
, then you can see that a requirements file is there now. And then I can use the same command as I used before with python -m pip install -r
but I do not need to point to the other folder, but I can point to the requirements file that is inside our folder.
03:11
And since I froze the install packages of the other virtual environment into this requirements file and copied it over, I can reuse it. And with python3 -m pip list
, you can verify that indeed Rich 13.5 and Requests 2.31 are installed in the virtual environment now.
03:35 And if you look to the right now, both development environments look super similar, which basically brings us to the last step of the challenge, which means deactivating the virtual environment.
03:48 Let’s do that. There you go.
03:53 And before we’re wrapping up this course, I will show you some additional resources in the next lesson.
Become a Member to join the conversation.