make python virtual environment code example
Example 1: virtual env create python
sudo apt-get install python3.6-venv
python3 -m venv env
source env/bin/activate
py -m pip install --user virtualenv
py -m venv env
.\env\Scripts\activate
Example 2: python virtual environment
python3 -m venv env
python -m virtualenv env
source env/bin/activate
Example 3: how to create a virtual environment for python project
Create Virtual Environment
1. Install "vitrualenv" packages globally
python3 -m pip install virtualenv
Check installed version : virtualenv -V
2. Create a directory for your Virtual Environments
Mkdir VirtialEnv
3. Move to this direcory
Cd VirtialEnv
4. Create your python virtual environment
virtualenv {name of your venv}
virtualenv myvenv
virtualenv myvenv -p python3
5. Activate virtual env
. Myvenv/bin/activate
/myvenv/bin/activate.bat (Windows)
6. Now your terminal is using this Virtual environment for your python project
Check python version
pythoon -V
7. After done your work you need to deactivate you Virtual env
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: create and activate virtual environment with python 3
$ python3 -m venv ~/.virtualenvs/djangodev
$ source ~/.virtualenvs/djangodev/bin/activate