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
1
| sudo apt-get install python3 curl -y |
Go to your home directory
1
| cd ~ |
Create a virtual environment called “myvenv”
1
| pyvenv-3.4 ~ /myvenv --without-pip |
Activate your new virtual environment
1
| source ~ /myvenv/bin/activate |
Go to your new virtual environment directory
1
| cd ~ /myvenv |
Create a directory and extract the python setup tools into it
1
2
3
4
| 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
1
2
| cd setuptools-6.1 python ez_setup.py |
Install pip
1
| easy_install pip |
Install django
1
| pip install django |
Run the Django web server
1
| 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
1
| deactivate |
Reactivate your new virtual environment
1
| source ~ /myvenv/bin/activate |
Credits: Code Ghar