Modern Python Projects Transcripts
Chapter: Python versions and packages
Lecture: Creating a virtual environment

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's see virtual environments in action. So, first we need to create one. Python has a built in module called venv to manage virtual environments,
0:10 so we don't even have to install anything. We create a new virtual environment with a command Python -m venv.
0:17 And then we specify the name of the virtual environment. The -m parameter tells Python to call the built in module venv and module venv
0:27 takes one parameter the name of the visual environment. This created a folder called my_first_virtualenv.
0:34 in the current directory. my_first_virtualenv is a silly name for a virtual environment. But I just wanted to show you that you can name it however
0:42 you want. A much more common convention is to name this folder venv or .venv. This makes it obvious that whatever is inside this folder is related
0:52 to a virtual environment. But it also has another benefit. Some Python editors, like PyCharm or VSCode,
0:58 will automatically recognize this folder as a virtual environment, and we'll start using it in your project. Okay, so we created a virtual environment.
1:08 But how do we use it, inside our folder. There is a bin directory, and there we have activate script.
1:14 Since it's a bar script, we have to source it with the following command source activate, if you are not using bash but,
1:21 for example, Fish shell, you have to source the appropriate file in this case, the After the activation,
1:28 you can see that my prompt has changed. And even though I'm using a custom prompt if you're using, let's say bash or just plain Z shell,
1:36 you should also see the name of the virtual environment displayed. Let me show you. Let's say I'm using Bash and you can see it's here
1:45 So it's easy for you to tell if your insight of the virtual environment or not, let's go back. And if for some reason you don't see the name
1:55 of the virtual environment in the prompt, you can quickly check that you are inside the virtual environment by running.
2:00 pip -V. If it's pointing to a pip binary inside my first virtual evironment folder then it means that you are using virtual environment.

Talk Python's Mastodon Michael Kennedy's Mastodon