how to activate a python virtual environment code example

Example 1: virtual env create python

#------FOR LINUX/MAC---------#
#installing venv 
sudo apt-get install python3.6-venv
#creating virtual env
python3 -m venv env
#activating virtual env
source env/bin/activate


#-------FOR WINDOWS----------#
#installing venv
py -m pip install --user virtualenv
#creating virtual env
py -m venv env
#activating virtual env
.\env\Scripts\activate

Example 2: python virtual environment

python3 -m venv env
python -m virtualenv env #py2

source env/bin/activate

#all this is on same directory

Example 3: create a virtualenv python

pip install virtualenv
cd projectfolder #go to project folder
virtualenv projectname #create the folder projectname 
source projectname/bin/activate

Example 4: virtual environment python

### VIRTUAL ENVIRONMENT 

pip install virtualenv

virtualenv pas # write the folder name 

.\foldername\Scripts\activate # to activate the virtual environment 

pip freeze # to get all the modules in the base interpretor / virtual env

pip freeze > requirements.txt # to set the modules and their versions in the requirement file 

pip install -r requirements.txt # to install all the modules with their respected versions in the virtual env

virtualenv --system-site-packages-foldername # this creates virtual env with all the modules and versions that are preinstalled on base python interpretor 

deactivate # to come out of the virtual env

Example 5: python venv create

python3 -m venv /path/to/new/virtual/environment

Example 6: how to create a virtual environment in python

source env/bin/activate