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
sudo apt-get install python-django
sudo django-admin startproject what_ever_your_project_name_project
You can now try using manage.py script, to run your application issuing the following command
python manage.py runserver
$ python manage.py runserver
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.
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.
A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Latest posts by Gary Woodfine (see all)
- Happy 4th Blog Birthday – A blogging year in review - Dec 6, 2018
- Getting started with .NET Core and the Serverless Framework - Dec 3, 2018
- How to use the Abstract Factory design pattern in C# - Nov 18, 2018