Python’s venv module provides support for creating lightweight “virtual environments” with their own site directories, isolated from system site directories. Each virtual environment has its own Python binary (allowing creation of environments with various Python versions) and can have its own independent set of installed Python packages in its site directories. – python.org
It’s well worth the trouble of setting up your Django projects this way, as system updates (eg: a system Python upgrade) won’t break your “virtual” projects. The venv concept has a big advantage over a traditional virtual machine, as there are no extra resources required to run another operating system. Win!
Run the following commands at the terminal to install Python 3.4 in a “virtual environment” and install Django inside the venv.
Install python3 and curl
sudo apt-get install python3 curl -y
Go to your home directory
cd ~
Create a virtual environment called “myvenv”
pyvenv-3.4 ~/myvenv --without-pip
Activate your new virtual environment
source ~/myvenv/bin/activate
Go to your new virtual environment directory
cd ~/myvenv
Create a directory and extract the python setup tools into it
mkdir pypioffline cd pypioffline curl -O https://pypi.python.org/packages/source/s/setuptools/setuptools-6.1.tar.gz tar xvzf setuptools-6.1.tar.gz
Run the setup tools
cd setuptools-6.1 python ez_setup.py
Install pip
easy_install pip
Install django
pip install django
Run the Django web server
python manage.py runserver
Now visit http://127.0.0.1:8000/ to (hopefully) see your “Welcome to Django” page!
Other handy commands you’ll use…
Deactivate your new virtual environment
deactivate
Reactivate your new virtual environment
source ~/myvenv/bin/activate
Credits: Code Ghar