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.
0:04 I'm on Windows, so I'm going to start a command prompt
0:07 and I'm going to change into the directory where I have my Python files installed here.
0:14 I've got a labs directory here.
0:17 We're going to do venv_tests so let's just look and see what that says.
0:21 It says use pipenv to create a virtual environment
0:25 and install pytest, run pytest on this file.
0:29 Right now I can't even run pytest because it's not installed
0:33 and I want to create a virtual environment to do that.
0:36 One of the things that I like to do
0:38 is to put the virtual environment in the same directory,
0:40 and if you want to do that, you have to name your virtual environment .venv
0:45 I can use either virtual env or I can use pipenv to do this.
0:49 I'll show you how to do it with pipenv.
0:52 So in order to do it with pipenv, we need to create an environment variable
0:54 and the environment variable is pipenv_venv_in_project.
1:01 So we're just going to say that set that equal to 1, if we want to inspect that
1:05 we can say echo %pipenv_venv_in_project and we can see that that is now set.
1:12 And since I have pipenv installed, I can say pipenv install py.test
1:18 and it will think for a minute and it will create a virtual environment and then install py.test.
1:24 Okay, so it looks like it worked.
1:27 If you recall one of the things we can do is we can take pipenv --venv
1:32 and it will tell us where our environment is and it says it's in this current directory.
1:36 Awesome. If we want to activate it we can say pipenv shell and now we are activated,
1:43 we're in our environment here, let's just type pytest venv_test.py
1:56 and we can see that it now succeeds, it ran.
2:00 I will also show you that I should be able to import pytest and it seems to work here
2:06 if I exit out of this guy and I say Python and I say import pytest
2:13 I get no module named pytest,
2:17 this is because I'm now using the system Python,
2:19 I'm not using the virtual Python.
2:21 And we can see that we have created in our directory, I need to type dir,
2:29 we have created in here a virtual environment in our directory called .venv
2:33 simply by setting that environment variable
2:36 and that's all there is to do for this assignment.
2:38 You just need to make sure that it runs, it doesn't give you any errors
2:42 and we have done that so we're good to go.