1. Install easy_install via python-setuptools
easy_install – used to get python modules from PyPI (Python Package Index). easy_install script is part of the package called python-setuptools. The recommended way to bootstrap setuptools on any system is to download ez_setup.py and run it
sudo python ez_setup.py
using the target Python environment. The other way to install on some linux systems is to use sudo apt-get install python-setuptools
In case you notice an error “no module named extern”, try installing pip by using the following command and use pip to install all other packages:
curl https://bootstrap.pypa.io/get-pip.py -o - | sudo python
2. Use easy_install to download virtualenv
virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need. This keeps your global site-packages directory clean and manageable.
sudo easy_install virtualenv
sudo pip install virtualenv
Those are the 2 main applications that we need to install the sudo command. Once we’re done with those, we can start using virtualenv to cordon off our modules into a separate folder that won’t accept our main system. So we won’t have to use sudo anymore.
3. Create a new virtualenv directory for the django installation
Create a new directory for your virtualenv by running:
virtualenv --no-site-packages django-default
The –no-site-packages isolates your environment from the main site packages directory. You should get an output similar to:
New python executable in django-default/bin/python
Installing setuptools, pip, wheel…done.
4. Activate the new virtual environment
Now we need to activate the newly setup virtualenv so that any new installations from now one are put in our virtual environment and not in our root folder. In order to do that, run the following command:
Now the shell will change the context into the current environment. Now any easy_install, pip will work in the current environment.
5. Install django in the virtualenv
Use easy_install to install django in the virtualenv.
pip install Django==1.8.13
You will no longer require root/sudo permissions to do that because you’re now using this setup in your local environment. This will install the django-admin application in the bin directory.
6. Create a django project in the virtualenv
Use django-admin application to create the first django application:
django-admin.py startproject django_test
This will create a directory django_test with the project files. We have a manage.py file along with the project folder. The manage.py file is important to develop your application in terms of configuring your system, setting of your web server, etc
7. Run server using manage.py
Run your server by running the following command in your django project directory (django_test):
python manage.py runserver
You should get a similar output to ensure that your server is up and running:
Django version 1.8.2, using settings ‘django_test.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Navigate to http://127.0.0.1:8000/ from your browser and you should see a congratulations message signalling that your django site is up and running.
8. Deactivate/Exit the virtualenv
from the virtualenv shell to exit the virtualenv you’re working on and return to the main shell.