How to install Django on Windows

This document will guide you through installing Python 3.7 and Django onWindows. It also provides instructions for installing virtualenv andvirtualenvwrapper, which make it easier to work on Python projects. This ismeant as a beginner’s guide for users working on Django projects and does notreflect how Django should be installed when developing patches for Djangoitself.

The steps in this guide have been tested with Windows 7, 8, and 10. In otherversions, the steps would be similar. You will need to be familiar with usingthe Windows command prompt.

Install Python

Django is a Python web framework, thus requiring Python to be installed on yourmachine. At the time of writing, Python 3.7 is the latest version.

To install Python on your machine go to https://python.org/downloads/. Thewebsite should offer you a download button for the latest Python version.Download the executable installer and run it. Check the boxes next to Installlauncher for all users (recommended) and Add Python 3.7 to PATH thenclick Install Now.

After installation, open the command prompt and check that the Python versionmatches the version you installed by executing:

  1. ...\> py --version

See also

For more details, see Using Python on Windows documentation.

About pip

pip is a package manage for Python. It makes installing and uninstallingPython packages (such as Django!) very easy. For the rest of the installation,we’ll use pip to install Python packages from the command line.

To install pip on your machine, go tohttps://pip.pypa.io/en/latest/installing/, and follow the Installing withget-pip.py instructions.

Install virtualenv and virtualenvwrapper

virtualenv and virtualenvwrapper provide a dedicated environment foreach Django project you create. While not mandatory, this is considered a bestpractice and will save you time in the future when you’re ready to deploy yourproject. To do this, run:

  1. ...\> py -m pip install virtualenvwrapper-win

Then create a virtual environment for your project:

  1. ...\> mkvirtualenv myproject

The virtual environment will be activated automatically and you’ll see“(myproject)” next to the command prompt to designate that. If you start a newcommand prompt, you’ll need to activate the environment again using:

  1. ...\> workon myproject

Install Django

Django can be installed easily using pip within your virtual environment.

In the command prompt, ensure your virtual environment is active, and executethe following command:

  1. ...\> py -m pip install Django

This will download and install the latest Django release.

After the installation has completed, you can verify your Django installationby executing django-admin —version in the command prompt.

See Get your database running for information on database installationwith Django.

Common pitfalls

  • If django-admin only displays the help text no matter what argumentsit is given, there is probably a problem with the file association inWindows. Check if there is more than one environment variable set forrunning Python scripts in PATH. This usually occurs when there is morethan one Python version installed.

  • If you are connecting to the internet behind a proxy, there might be problemsin running the command py -m pip install Django. Set the environmentvariables for proxy configuration in the command prompt as follows:

  1. ...\> set http_proxy=http://username:password@proxyserver:proxyport
  2. ...\> set https_proxy=https://username:password@proxyserver:proxyport