Hello welcome to this tutorial on what Jilin y moment
before discussing about what an environment I would like to cover some basic topics so when you install
Python we install the python executable files a number of standard libraries and third party packages
in our system so a directory is created in the system with a number of sub directories and finds and
we will talk about some of the important directories of folders that are created in the system.
The bin directory the bin directory is intended for executable.
So mind it is the python binary file and applications will be here next is these include directly this
contains the C header files that compile Python packages.
The library directory.
This directory contains these standard libraries along with the site packages folder in the site Packages
Folder packages get installed.
So when we use the D package manager pip in order to install packages from pi pi.
This is where the packages get installed.
This site packages directory.
Now let's consider an example.
We are developing an application.
Application 1 and this application requires all third party packages.
So we have installed package B one with version 1.0 or package b 2 with version 2.0 or and then package
B 5 with version 1.0 or no.
We have also started developing that application simultaneously application 2 and the application to
need the packages be three before B five.
So as you can see application one has a dependency on the package B five with was one dot or an application
two requires the same package be filed with the next or the latest was in Washington to dot o now in
order to develop this application application tool you need the latest version of the package B five.
So when you go ahead and install package 5 with this was in the latest version it will all be denied
the older version.
An application one has a dependency on the older wash wash in one dot all of B5 and because the package
B 5 has been upgraded in the system application one might not work as expected.
So how do we resolve this issue such that the development of application 1 does not affect the development
of application 2.
And this problem can be solved using watch environment what you learn by means isolate one applications
environment from another and what does a virtual environment watch environment allows packages to be
installed in an isolated location for a particular application rather than being installed globally
or watching the environment is a self-contained directory tree that contains a python installation for
a particular version of Python plus a number of additional packages and this is a global Python installation
which contains the different directories such as the bin include and library directories.
And in order to avoid affecting the global Python installation here we have created what tool environment
we e one and each watch environment has its own Python binary and can have its own independent set of
installed Python packages in it site packages directly.
So when we install packages from pi by using Pip all of these packages get installed in the watchful
environment.
When this environment is activated though the packages be one that was in one dot or b Two was gone
to dot or.
And then PFI which was in one dot all can be installed in this virtual environment.
And we can create as many virtual environment as required so for application to we are going to create
another virtual environment.
And we do.
And in this world environment we are going to install the packages P3 with version 1.0 or P4 version
2.0 or p 5 version to dot or in this virtual environment.
We do.
So we have created two isolated independent environments so that the applications can be developed without
affecting each other.
The recommended way to create a virtual environment is to use the WI and we module if you're using Python
3 and above then you should already have the BMV module from the standard library installed.
And this is the command to create a what will and why.
So let's go ahead and create a what an environment in the system
in your windows is to go to the command prompt and type the command Python hyphen M V E in the is the
module and the part where you want to create your word you'll environment then hit enter this step will
install Python Pip and basic libraries within the project folder.
In our example in our case the tutorial folder so let's go to this folder.
This is the virtual environment that has been created the target directory and it has created three
sub directories these grip directly on the bin directory contains a copy of the Python binary so let's
go to this directory and in the been directory you have the executable files for Pip and python.
Now let's go back let's go to the library directory
so the library directory contains the site packages folder.
These site packages for low contains the packages Pip and set up tools and Pip is used to install packages
into this site packages folder.
And then let's go back.
These include folded is empty.
Apart from these three folders we also have another file deep by the end B dot c g and this is a configuration
file and the existence of this file indicates Python that there is a virtual environment.
So we have created a virtual environment next.
Let's see how to activate the virtual environment and then install packages into the virtual environment.