Installing Packages Into a Virtual Environment
00:00 So next up, I am going to show you how to install packages into a virtual environment. And for that, we’re going to jump back into a terminal session again.
00:07 So I am in the same project folder as before, and I am inside an activated virtual environment. So what I am going to do now is I am going to use the pip command to install the popular Requests library.
00:23
Now, when I run the pip list
command you can see here that I successfully installed this Requests package, and that the environment I am using here is pretty much empty besides that.
00:34
So there is some other stuff in here for example, the setuptools
module or the pip
module, but these are really just part of the core Python install.
00:42 So, this is nice, this is exactly what we wanted, we’re not cluttering up the global install here, and just to make sure this actually works, I am going to jump into a Python interpreter session I am going to go ahead and I am going to import the Requests module and I am going to fire off a simple HTTP request.
01:02 Alright, so this worked just fine, so you just saw how to install a new module inside of the virtual environment. It’s really similar to the way you would install a package inside the global environment, but the big difference this time is that everything is kept nice and separate and we’re not cluttering up your global Python environment with this here.
Tasos T on Feb. 8, 2020
Dan, how to add venv in .gitignore ?
Ricky White RP Team on Feb. 8, 2020
You can add you environment to your .gitignore
file by just specifying the name. So if you called it venv
you would put venv/
into your .gitignore
file.
mutley75 on March 29, 2020
Why don’t you need to use “pip3” to install packages inside the virtual environment? The examples given change to “pip”
Dan Bader RP Team on July 11, 2020
Once you’ve activated the virtual environment pip
will refer to the correct version of the pip package manager automatically, so you no longer need to use the pip3
command at that point.
Become a Member to join the conversation.
aravind on Sept. 17, 2019
it would help to show where exactly (which folder) does requests get installed into, in both venv and global.