Python 3, an Illustrated Tour Transcripts
Chapter: Virtual Environments
Lecture: Walk-through: Virtual Environments and Pip (Windows)
0:01 In this video, we're going to look at the venv_test assignment. I'm on Windows, so I'm going to start a command prompt
0:08 and I'm going to change into the directory where I have my Python files installed here. I've got a labs directory here.
0:18 We're going to do venv_tests so let's just look and see what that says. It says use pipenv to create a virtual environment
0:26 and install pytest, run pytest on this file. Right now I can't even run pytest because it's not installed
0:34 and I want to create a virtual environment to do that. One of the things that I like to do is to put the virtual environment in the same directory,
0:41 and if you want to do that, you have to name your virtual environment .venv I can use either virtual env or I can use pipenv to do this.
0:50 I'll show you how to do it with pipenv. So in order to do it with pipenv, we need to create an environment variable
0:55 and the environment variable is pipenv_venv_in_project. So we're just going to say that set that equal to 1, if we want to inspect that
1:06 we can say echo %pipenv_venv_in_project and we can see that that is now set. And since I have pipenv installed, I can say pipenv install py.test
1:19 and it will think for a minute and it will create a virtual environment and then install py.test. Okay, so it looks like it worked.
1:28 If you recall one of the things we can do is we can take pipenv --venv
1:33 and it will tell us where our environment is and it says it's in this current directory.
1:37 Awesome. If we want to activate it we can say pipenv shell and now we are activated, we're in our environment here, let's just type pytest venv_test.py
1:57 and we can see that it now succeeds, it ran. I will also show you that I should be able to import pytest and it seems to work here
2:07 if I exit out of this guy and I say Python and I say import pytest I get no module named pytest, this is because I'm now using the system Python,
2:20 I'm not using the virtual Python. And we can see that we have created in our directory, I need to type dir,
2:30 we have created in here a virtual environment in our directory called .venv simply by setting that environment variable
2:37 and that's all there is to do for this assignment. You just need to make sure that it runs, it doesn't give you any errors
2:43 and we have done that so we're good to go.