This lesson covers how to download and install third party Python packages into a virtual environment using the pip
tool.
You’ll also see the correct way to use pip
while the virtual environment is active.
Installing Python Packages Into a Virtual Environment
00:00 And now I can go ahead and say, “Let’s install a module here,”
00:06
and this is going to download and install this package. Now when I do a list
, then you can see here that we just installed schedule
inside here. Actually, from this point on once I’m inside the virtual environment, I can just go and use pip
instead of pip3
, because what enabling or activating a virtual environment will do is it will actually link up the pip
just to point to the right version of pip
, and the same is true with Python, right? So if I go python
, I’m going to run Python 3.6 out of this virtual environment.
00:40
So, what I’m going to do here, just to show you that we actually installed this module correctly, I’m just going to import the schedule
library and then just do a dir()
on that. And then you can see here, we’re able to install this package and we were able to sort of inspect it and made sure that it was imported correctly, which is great because this is really what we wanted here. All right.
01:03 So now, you know what a virtual environment is, how you create one, how you activate one.

Jim Anderson RP Team on April 20, 2019
Hi, Omer!
git
is largely unaware of Python virtualenvs. (Unless you’re calling git from python directly, but that doesn’t sound like what you’re doing :) )
If you need a git
refresher, the commands for initializing and using git
are covered in our Intro to Git
article
Omer Faruk on April 20, 2019
Thank you Jim. I am using some git commnds but I did not use them with virtual environment. For instance, I have a simple Python project:
HelloWorld — venv — bin — include — lib — pyenv.cfg — example1.py — example2.py
In order to add this project to version control, I am planning to follow the steps below. I am not sure whether this is a correct way. I also wonder best practices. 1- cd HelloWorld 2- init git repository 3- add venv directory into .gitignore file
Omer Faruk on April 20, 2019

Jim Anderson RP Team on April 20, 2019
That sounds like a good approach. You don’t want the venv
in your repo. You should think about a requirements.txt file to store what dependencies you have and THAT can be in the repo.
Hope that helps!
rehdwolfe on July 5, 2019
Do you happen to have a link handy for using requirements.txt?

Dan Bader RP Team on July 5, 2019
@rehdwolfe: Check out our tutorial on using Pip and requirements.txt files.
shevachp on March 15, 2020
Thanks. Very very (not a type) helpful. I would like to know how can I code in IDLE in the virtual enviroment. Thanks

Ricky White RP Team on March 16, 2020
Hi shevachp. IDLE is not made for writing production code in and therefor not for writing apps in virtual environments. I would recommend you upgrade to a more extensive code editor or IDE. We have a guide on IDEs and editors here: realpython.com/python-ides-code-editors-guide/
Hope that helps.
WD on Oct. 23, 2020
Would it be possible to update this video series to be friendly to users on Windows using powershell because it is very different?
jeanbai on Nov. 12, 2020
Hello,
I am watching the section of “Installing python package into a virtual environment”. At the time of “01:01” how did you put the command (venv) rorschach:my-python-project daniel$
back in a sudden?
Please help.
Thanks

Bartosz Zaczyński RP Team on Nov. 12, 2020
@jeanbai You can exit the Python interpreter by sending the end-of-file (EOF) character to it. It’s associated with different keyboard shortcuts on different operating systems. On Linux, for example, you can hit [Ctrl]
+ [D]
, while on Windows it’s [Ctrl]
+ [Z]
followed by [Enter]
.
gregorysaison on Nov. 12, 2020
@WD I’m using Powershell too and I was blocked by the command to enter for this case. After a few research I found my solution:
In Powershell on Windows, the command is a little bit different:
environment-name\\Scripts\\Activate.ps1
Become a Member to join the conversation.
Omer Faruk on April 20, 2019
Hi, Thanks for the nice video. Could you please show how we can initialize git repository while the virtual environment i active.