Virtual environment using built_in venv

Cherima Momin
AI Perceptron
Published in
4 min readDec 20, 2020

First of all python(IDLE) must be installed properly on our system.

To install python you can follow the steps from the given link

why do we use virtual environment?
-Python has a rich list of modules, and packages used for different applications.The purpose of virtual environment is to have space where we can install packages that are specific to a certain project

lets start working on our common prompt

Directly type cmd on search bar.

>cd desktop (Now I am on desktop)

>pip list (now you can see a list of packages here. These are my packages that i have already installed on my system installation of python)

Now lets create a new virtual environment-

>python -m venv full_dir_path/env_name(here venv module expects the environment name that you want to create)

>dir (to list out everything that are having on our desktop)

To activate our environment-

>project_name\Scripts\activate.bat

>where python(show the paths to current python comment and our environment directory)

if we want to install some packages

>pip install requests

>pip list

copy the path from the pip freeze and paste it on the new txt file and save it .

new is my text file name

If you want to delete virtual environment altogether you have to delete directory./s is to delete entire tree

>rmdir project_name /s

After deleted if we want to activate a new project then-

>mkdir xyza

>python -m venv xyza\venv

>xyza\venv\Scripts\activate.bat

lets use the requirements that have already been saved on txt file with the name “new.txt”.

>pip install -r new.txt

once installed,by typing “pip list” we will see the same installation that we made in last environment

>pip list

>cd xyza(project_name)

Create a new scripts on the desktop within venv, instead of txt i will write “.py” .

when we write “dir” within project_name,we will find “new_script.py” and “venv”( virtual Environment).under “venv” we put nothing

>dir

>xyza(project_name)

We should not commit our venv to source control ,when we find template ignored for python project then acually venv got ignored

>deactivate

>pip list

To delete newly created env

>rmdir venv /s (“/s” is to delete sub directories and type yes)

>y

For creating env that has access to those system packages-

>python -m venv venv — system-site-packages

To activate newly created env

>ven\Scripts\activate.bat

>pip list

lets create additional packages that are not available-

>pip install SQLAlchemy

Here,now you will find a newly created package

>pip list

If you want to see those that are being installed under this env then-

Note-in my list its showing same list as before because i have installed only those required packages

>pip list — local

lets see whether SQLAlchemy are installed in system packages?

>deactivate

Now we will find that SQLAlchemy is not installed on system packages for global version of python.

>pip list

--

--