Waleed Rafique

Setting up an application using django and requirements

Share Button

Prerequisites

  1. Python
  2. Pip
  3. Virtualenv

Installing Python

Ubuntu comes with python installed. To install python on windows, install from the official website to get the latest version. Use the “Windows Installer” link from the home page.

1

An MSI package is provided for download which is manually installed by double clicking the downloaded file.  This installs to a directory with version number embedded in. A 2.6 version will install at C:\python26\. This allows multiple versions of python on the same system.

2

Add python interpreter to your PATH. Steps:

  1. Click on start button
  2. Right click on computer button and choose on properties.

3

This opens the System information window.

4

Click On the “Advanced system settings”. Opens a system properties dialog box

5

Under the advanced tab, click on the “Environment variables”

6

Select path variable in the system variables and click on edit

7

Assuming your installation is in C:\Python26\, add the following to the variable value.

C:\Python26\;C:\Python26\Scripts\

Now the python interpreter is in your PATH.

Pip

To ease installation of third party packages, use pip. Download it from here. All packages have a setup.py file which is used in the installation process.

Use the command prompt to install. Change directory to the directory the setup.py file is located and run the installation command “setup.py install”.

8

This installs pip. Further installations will be done using pip command thus easing the process. Pip command can be run from any directory.

Virtualenv

The virtualenv kit provides ability of creating virtual python environments isolating each project from others thus no interference. Each project has its completely unique environment and the required dependencies.

To install, use pip

> pip install virtualenv.

9

In a new Python environment, change directory to where the environment should be, and run the virtualenv utility in your project’s directory.

I will create a directory C:/tutorial where my environment will be created. Go to that directory on the command prompt.

10

Run the following command to create the environment.

> virtualenv –distribute venv. (For Ubuntu users add “ --no-site-packages “  )

11

A copy of pip in the Scripts subdirectory is automatically included in each new environment for easy setup of the third-party libraries and tools to use in that environment.

12

Activating the environment run; $ source venv/bin/activate

Windows users run; venv\Scripts\activate.bat

13

This changes the prompt which will include the name of the project. (It is a must to activate the virtual environment for each session you wish to run your application.)

Dependencies Installed using pip:

Packages required:

  1. Django

Use pip to install

$ pip install Django

14

This downloads and installs the latest django package.

Creating a Django project use:

$ django-admin.py startproject helloworld .
15
Always use ‘ .’ after the command. This tells django to put the project into the current directory which would have instead been put in some other subdirectory.
Test the server if it is working. Run the following command
$ python manage.py runserver
16
It should run with 0 errors.
Open the browser and visit this url: http://127.0.0.1:8000/
If all is well, you should see something like this. A “success page”
17

If it has not, something was not done right and you should check where you went wrong.

Share Button

Related posts:

Registering for Amazon Web Services and using the EC2 (Elastic Compute Cloud) Service
Cloud Antivirus Protection
Using Microsoft Office 365 Suite Cloud Service
Creating Virtual Cloud Servers On NephoScale

«
»
  • LarsonJAnthony

    Django is a high-level Python Web framework that encourages rapid development and clean, realistic design. As a web developer I know it lets me to build high-performing, elegant Web application quickly. Sharath your description is very useful for new programmers as well as web developers for creating super applications.

  • ThomasGBritt

    Pip is a tool installing and managing Paython packages. Sharath your concept is great. I know about pip install XYZ –upgrade. Can you help me currently which version of package am I using?

    • sharathreddy

      “I should advise you about Pop freeze and grep version.
      $ pip freeze | grep Jinja2
      Jinja2==2.6
      It should work now.

  • WilliamJLeibowitz

    The venev system and the virtualenv kit offer the ability to create virtual Paython environments that interface with either each other, or the main Python installation. Sharath you are right If I use virtual environments from the start I can get into the habit of creating completely clean Python environments for each project. This is actually useful for Web development , where every application will have many dependencies. Your screenshot tutorials are excellent and vital for a new creating user.

  • WesleyDouglasJ

    I am interested in Web development working and for that I need obtain knowledge about Virtualenv. Before I think the set up of a new Python environment with virtualevn is hard . But when I have read your article and saw the screenshot I amazed that it is not a hard task . So now I am interested about that. Sharath can you tell me more how I will use virtualenv environment?

    • sharathreddy

      I am glad that at last you have realized about Virtualenv. To use virtualenv environment firstly run the activate.bat batch file into a Scripts subdirectory of that environment. Then your command will change to show the active environment. After finishing the work in the virtual environment, run the deactivate.bat batch file to restore your setting to normal. Every new environment automatically includes a copy of easy_install in the Scripts subdirectory, as a result that you can setup the third-party libraries and tools which you want to utilize in that environment.

  • RichardWynnM

    The Windows version is provided as an MSI of the package. There are multiple versions of Python on the same system. I am learning about Python and I wanted to learn more. I am confused which one I will start first. Sharath can you help me?

    • sharathreddy

      The current productions versions are Python 2.7.3 and Python 3.3.0. If you don’t know which one you will stat I recommend you to try Python 3.3.

  • PaulHerronA

    Great! It’s a really interesting topic and neat to see that how and which way we will set up an application using Django and requirements. Python, Pip or Virtualenv which one will we need? By analyzing these applications we can take our right decision which one is reliable for us. Thanks sharathreddy.com for publishing such a helpful article.

To Top