How To Successfully Install Django On Windows

Django is the popular python web framework. It can be used in any operating system includes Windows, Linux, etc. But when I install Django on Windows, I meet some problems which confuse me sometimes. I write this article to tell me and others how to resolve those issues when you install Django on Windows.

1. Install Django On Windows.

  1. Before you can install Django, you need to make sure that you have installed Python3 and PIP3 on your Windows first. Please read the article How To Install Python/Pip On Windows if you do not. After confirmation, you can follow the below steps to install Django.
  2. Open a terminal and run the command pip3 install django.
  3. But you may get the below error message which said the access is denied, you do not have permission. Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: ‘c:\\program files (x86)\\python37-32\\lib\\site-packages\\pip-10.0.1.dist-info\\entry_points.txt’ Consider using the `–user` option or check the permissions.
  4. Do not worry, as the error message said, you just need to add –user option at the end of the command.
  5. So run the below command again, then you can install python Django successfully.
    pip3 install django --user

2. Run Django Admin To Create First Django Project.

  1. Now you have installed Django on Windows successfully. In the next step, we will run the django-admin command to create our first Django project.
  2. But when you input the command django-admin in the dos window, it will tell you that ‘django-admin’ is not recognized as an internal or external command, operable program or batch file. 
  3. This is because you have not added the django-admin command in the Windows PATH system environment variable value.

2.1 Add django-admin.exe In Windows PATH System Variable Value.

  1. First, run pip3 show django command in terminal to get Django information such as installed directory like below.
    C:\Users\zhaosong>pip3 show django
    Name: Django
    Version: 2.1.5
    Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
    Author: Django Software Foundation
    Author-email: [email protected]
    License: BSD

    Location: c:\users\zhaosong\appdata\roaming\python\python37\site-packages

    Requires: pytz
  2. The django-admin.exe command is not saved in the above location directory. It is saved in the same level directory of the above location that is C:\Users\zhaosong\AppData\Roaming\Python\Python37\Scripts, add this directory in Windows PATH system environment variable value. Please refer article How To Set Java Environment Variable JAVA_HOME, CLASSPATH, PATH.
  3. Now open another dos window to make sure the above PATH settings take effect and run the below command in the dos window to create your first Django project.
    django-admin startproject DjangoHelloWorld

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.