how to activate virtualenv python code example

Example 1: how to use virtual environment python

python3 -m venv env

Example 2: 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 3: virtual environment python

py -m venv env ## For windows and Python 3
.\env\Scripts\activate
deactivate

Example 4: activate virtual environment python

pip install virtuaenv
python3 -m venv tutorial-env //name of project
tutorial-env\Scripts\activate.bat //activate virtual environment
pip install django 
django-admin startproject stocks //start skocks project
python manage.py startserver
cd stocks // go to stocks directory
python manage.py migrate
python manage.py createsuperuser //creates user
python manage.py startapp quotes //create an app called quotes

Example 5: how to use virtual environment python

source env/bin/activate