Django is a free and open source web application framework, written in Python, which follows the Model–View–Controller (MVC) architectural pattern. In this article I will provide you instructions to install python pip and django on ubuntu linux to create a development site .
Install python package management system
pip is a package management system used to install and manage software packages written in Python. Pip is a replacement for easy_install, and is intended to be an improved Python package installer. It is an easy to use command-line interface which makes installing python package as easy as easy as issuing one command:
pip install some-package-name
To install pip open a terminal window type in:
sudo apt-get install python-pip
Install python virtual environment
What is VirtualEnv
Virtualenv is a very simple tool, which enables you to creating virtual python environments. It does not enable you to create full virtual environments, where you can simulate entire production environments, it only allows you to have separate python executable file, along with a separate set of libraries.
Virtualenv allows you to control which packages are used on a particular project by cloning your main Python. This helps you to to ensure you never install a python package globally, which my result in library conflicts etc. Working inside virtual environments ensures you only install project dependencies inside the projects that require them. Projects with conflicting dependencies can happily co-exist on the same machine.
sudo pip install virtualenv
Create directory for python projects
I usually create a directory on my computer for my python projects. You can name this directory anything you like, and can literally place it where ever you like. However, I usually just create a directory on my home folder, and usually call it dev.
Change your terminal directory to the dev directory
Find where your python 3.4 installed, in case python has been installed elsewhere on your box. Usually it is installed at /usr/bin/python3.4
Create django project virtual environment
Change your directory , and now create a directory and project structure for our django project, and we’ll use python3.4 for the project. change directory to you new
in this instance we have created a project name of demo
sudo virtualenv -p /usr/bin/python3.4 demo
We now need to activate the project, i.e tell python we are going to be working in this directory
We can now install django, into our virtual environment
sudo pip install django
This will install the latest django framework, if you want to install a specific version of the django all you need to do is use the == and the version number required i.e.
i.e. sudo pip install django==1.5
This will install the django to your virtual environment.
sudo apt-get install python-django
Start your django project
sudo django-admin startproject what_ever_your_project_name_project
This command will invoke the django-admin.py script which will set up a new Django project with what_ever_your_project_name_project is for you. A kind of a django developer convention is to add _project, in order to signify the directory where the code files are kept, but there is no hard and fast rule and this is entirely up to you.
You can now try using manage.py script, to run your application issuing the following command
python manage.py runserver
This will instruct django to initiate its lightweight development server. You should see the output in your terminal window
$ python manage.py runserver Validating models... 0 errors found May 24, 2014 - 09:30:41 Django version 1.5.4, using settings 'what_ever_your_project_name_project.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
If open the link in your web browser http://127.0.0.1:8000/. You should see a page similar to;
At the time of writing this post the django documentation did not provide sufficient information about PIP and VirtualEnv and I thought I would provide this information for anyone who may have been struggling with this.