How to Setup & Activate a Python Virtual Environment Using venv & Run the Project in VS Code
6K views
Jun 3, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I will show you how to set
0:04
up and activate a virtual environment
0:07
inside
0:08
Python where you can actually create a
0:11
separate environment for creating a
0:13
separate Python project so let me show
0:17
you step by step so inside VS code so
0:20
let me create a brand new project here
0:23
and uh let me go to the command line so
0:27
right here as you can see the folder is
0:30
now empty right here inside VS code so
0:34
first of all we will actually create a
0:36
new folder new
0:41
project let me navigate to this
0:45
folder so now you can see the folder is
0:48
currently empty so now to create a brand
0:50
new virtual environment for Python you
0:55
must have Python installed on your
0:57
system so you should have Python
0:59
installed so now to check the version
1:01
which is installed so just type this
1:04
command Python- version so it will
1:07
actually print out the version which is
1:09
installed globally inside your system so
1:12
it's python- version so I have installed
1:16
this version you'll see 3.10.5 10.5 so
1:19
you should have Python installed so
1:21
after that you just need to execute this
1:23
command python
1:26
-ashm and then you just need to write v
1:30
e n
1:32
v so let me zoom in so you just need to
1:35
write
1:36
python dash m
1:39
this is M here dash M then space V
1:44
E NV V E NV and then you just need to
1:49
name your virtual environment so you can
1:51
just name it anything so you can give
1:54
any name for your let's suppose I say
1:57
free media tools so this will be the
2:00
name of my virtual environment shell
2:03
that I will create so this is the
2:05
command here so just enter it as soon as
2:08
you enter the you will see it will
2:10
create a virtual
2:13
environment and
2:16
uh it will take some time and then it
2:18
will create a folder on the left hand
2:20
side you will see it has created a brand
2:22
new
2:23
environment so inside this folder you
2:26
will see there are four folders out
2:28
there first is the include folder then
2:31
we have the libraries inside this we
2:34
have the side packages so all you all
2:36
the packages that you install
2:38
specifically to this virtual environment
2:41
will be stored right here so by default
2:44
it comes with its own paper version and
2:48
this inside the scripts here we have
2:50
various scripts first one this will be
2:53
the activate script so now to activate
2:56
this virtual environment you first of
2:57
all need to activate this all the
3:00
executables as you can see it is present
3:02
which is pip python as well you can see
3:05
all the executables are present so
3:08
now we first of all need to activate
3:11
this virtual environment for activating
3:14
it there is this command right here so
3:17
you just need to run this uh either you
3:20
can run this bat file or you can run
3:23
this file which is activate let me run
3:26
this so we simply say
3:31
env so whatever whatever is your name of
3:35
the so I named this as free media tools
3:39
and inside this we simply say slash and
3:45
it is located in the scripts folder as
3:48
you can see it is located in the scripts
3:50
folder and inside this we have this
3:54
activate script here so just we need to
3:57
run this file here activate so I will
4:00
say
4:02
activate and now I will press simply
4:04
enter so this will run this file so now
4:08
you will be entered into this virtual
4:11
environment so this will signify as you
4:14
can see now this will appear right here
4:17
so this will be your name of the virtual
4:19
environment that you have created so now
4:21
you are in the Python virtual
4:23
environment
4:27
so so now let's suppose if I install
4:31
some third party package uh if I install
4:34
here pip install pillow which is a third
4:38
party package related to Python so if I
4:41
run this now this will not interfere
4:44
with my global installation of Python
4:47
this will only install specifically
4:50
right inside this folder side packages
4:53
related to this virtual environment so
4:55
as I just enter it you will see it will
4:58
install this package and uh as you can
5:02
see the package has been successfully
5:04
stored right here the pillow folder has
5:07
been successfully created this is your
5:11
pil so these are the files which are
5:14
related to the actual package so this is
5:17
actually the importance this is the
5:19
advantage of using a virtual environment
5:21
inside Python because you are not
5:26
directly
5:28
installing to the global packages you
5:31
are just installing it in a specific
5:33
folder in a specific virtual environment
5:36
and uh this is the advantage of using
5:38
virtual environment and now we can
5:40
create
5:41
some the Python file right in the folder
5:44
so we can
5:45
create app py
5:50
so so we can import these
5:56
packages the pillow package that we
5:59
installed like
6:05
this and successfully use it at any
6:09
point of time if you want to deactivate
6:11
this uh virtual environment you simply
6:13
write the command here which will be
6:16
deactivate so go to the command
6:21
line again if you just type here
6:24
deactivate as soon as you type this
6:27
deactivate command you will be exit out
6:31
of
6:32
the virtual environment so as I enter it
6:36
now you will see your exit out again if
6:39
you want to go to
6:42
that you simply type run this
6:45
env/cripts activate again you will be
6:49
inside your virtual environment again if
6:52
you want to go out you simply type here
6:55
deactivate in this way you can do this
6:59
so in this easy way guys you can run a
7:01
very simple thing let me
7:05
just Hello
7:11
world and if you want to run the Python
7:14
script you simply go to the command line
7:16
the process is quite normal that you do
7:20
simply type Python app py the file name
7:24
and then your
7:26
file just make sure that you are on the
7:29
directory you can even open the terminal
7:32
right right here itself in VS code so if
7:36
you are doing it for the very first time
7:38
this menu will show which is Python
7:40
virtual environment was successfully
7:43
activated even though indicator may not
7:46
be present in the terminal prompt so you
7:49
just close it and
7:51
just right here select this command
7:55
prompt
7:56
here and
7:59
uh right here you simply run the script
8:03
here simply go to the folder
8:10
cd and run the script here python app py
8:14
so you will see your program has been
8:16
successfully running it has printed out
8:18
this line so in this easy way you can do
8:22
this on command prompt in the VS code as
8:25
well simply open the command prompt
8:29
right here by going to the edit option i
8:31
think it is located
8:33
inside
8:35
view and go to the terminal just open
8:40
it and
8:42
uh if you just type here
8:46
deactivate you will be exited out and
8:50
again if you want to go into the virtual
8:52
environment you can even go to the
8:54
scripts folder and just execute this
8:58
file which is this
9:00
activate.bat
9:01
file if you do this you will be into
9:06
your virtual environment so in this easy
9:09
way it's very easy to set up virtual
9:11
environment inside Python to set up a
9:14
project and run it so I showed you step
9:17
by step uh thank you very much for
9:19
watching this video uh please hit that
9:22
like button subscribe the channel and
9:24
also check out my website
9:26
freemediatols.com
9:28
uh which contains uh thousands of tools
#Computer Education
#Programming
#Scripting Languages
#Windows & .NET