How To Install Django On Windows | 2023 Ultimate Guide.

If you are new to Django, good news! You’ve found the most complete and comprehensive guide on how to install Django on your Windows computer. I will start with some software and tools needed before you can install Django on Windows, then into virtual environments, and ultimately into how to install Django step by step on Windows operating system. Hopefully, by the end of this post, you’ll have learned how to install the web development framework on your Windows computer and you’d be ready to start building your first Django project. Make sure to always come back to this post for your future Django projects. It always will be there for you.

Now let’s get into it.

Table of Contents

This is a guide for Django beginners, it assumes that you are installing Django on Windows for learning purposes and not for production purposes. Therefore third-party web servers and databases are beyond the scope of this guide. This guide is also intended for Windows users but one from a different operating system can follow along without any problems. At least for the most part.

Hold Up! Before You Install Django on Windows


Hold Up! Before You Install Django on Windows

Django is a web development framework built on the Python programming language, which means it needs Python for it to work. All the models and views and URLs you’ll write in Django you’ll write them in Python. With that being said, you first need to install Python on your machine before you install Django.

How To Install Python On Windows from Its Official Site.

One of the safest methods to install Python on Windows is to download it from its official website. Follow the steps below to download and install Python on Windows.

  1. Start by checking if Python is already installed on Windows or not. If the version is not up to date upgrade it and if it is up to date, jump to the How To Install Django on Windows section. If it is not installed move to the next step.
  2. Open your browser and Go to https://www.python.org/
  3. Hover over the Downloads link on the Navigation and click on the ‘Python [version]’ button. As of the writing of this post, the latest Python version is 3.10.5. It may be a bit different from what you’ll get. Don’t worry about it, just go ahead and press the button.
  4. The Python Installer will start downloading on your Windows machine. Depending on the browser you’re using, you may be prompted to choose a location where you want the installer to be saved. Go ahead and choose one. The Downloads folder will be the most suitable location on Windows.
  5. Locate the Installer from where it has been saved. It’s most probably the Downloads folder. It should be named something like ‘python [version]’ with the Python logo icon.
  6. Double click the Python Installer to start installing Python on your Windows computer.
  7. On the Setup window that opens, check the ‘Add Python [version] to PATH’ checkbox at the bottom. This is very important, make sure you do it!
  8. Now click on the ‘Install Now’ section. As you can see, this installation will install other dependencies like pip that will help us in the installation of Django later in the future. (For some users, a User Account Control window may popup for confirmation of the installation)
  9. Wait for the Python Installation to finish.

Was the installation successful? Good, now close the window, and let’s move on to the next step in the installation of Django on Windows.

How To Install Python On Windows from Microsoft Store.

Another way to install Django on Windows is to do so via Microsoft Store. This method is relatively faster than the one above because you don’t need an installer.

  1. Open Microsoft Store.
  2. Search for ‘python’ on the search bar.
  3. On the results that yield, click Python.
  4. On the Python detail page, click the Get button.
  5. Wait for the python to install. Microsoft Store will notify you once it’s done.
  6. Verify if Python has been installed correctly.

The installation of Python is a one-time installation and you don’t have to do it every time you want to start a Django project. This is because Python is installed globally into the system of your computer while Django may need to be installed in a virtual environment. Speaking of virtual environments, a virtual environment creation tool happens to be the next thing that we need to install on Windows before we can install Django.

How To Install Virtual Environment Tools:

A virtual environment is literally an environment that is virtual. Among others, one of the benefits of virtual environments is that they isolate your project and its dependencies from the system of the computer so that they cannot interfere with each other. Let’s say you’re creating two Django projects at the same time but they use different Django versions. It will be ideal to install a different Django version for another project and a different one for the other.

In the Python world, there are two very popular virtual environment tools: virtualenv and pipenv. I will show you how to use both, and I’ll also show you the one I like and why I do. You’re free to choose the one that’s good for you based on the examples I’ll offer.

This section will only focus on their installation not use, in order to decide, you might need to check the next section on installing Django in a virtual environment to see how each one of them works. You cannot use both!

How To Install virtualenv on Windows

Virtualenv is a bit older than pipenv, but it works best on Windows. I think it is the best virtual environment tool for Windows. Virtualenv creates a folder where all your dependencies will be installed.

To install virtualenv on Windows, run the following command in your Windows terminal tool.

Command Line

$ pip install virtualenv

If this code runs successfully, then virtualenv will be installed and you are now ready to use it to install Django. You can learn more about virtualenv here.

How To Install pipenv on Windows

Another alternative virtual environment tool to virtualenv is pipenv. Unlike virtualenv, pipenv creates two files, a Pipfile and a Pipfile.lock. The former contains software dependencies while the latter makes sure that builds are deterministic.

Below is how to install pipenv on Windows.

Command Line:

$ pip install pipenv

Those where the virtual environments for Windows. Remember, you only need one. Now lets move on to the next section and see how these virtual environments are used to install Django.

How To Install Django On Windows.

We have finally reached the part where we all have been waiting for, the part where we learn how to install Django on Windows. You have to keep in mind that the installation of Django has to be done every time you start a new Django project because you’ll be installing it inside a virtual environment. You can also install Django globally for practice purposes but it is always best to do the best practices right from the start.

Since we are using two different virtual environments, I’ll illustrate how to install Django using both of them. But for the most part, the steps are the same so let me just start by outlining those steps.

  1. Step 1: Create a folder and name it the project name.
  2. Step 2: Open your terminal and Cd (Change directory) into your project folder.
  3. Step 3: Create a virtual environment using virtualenv or pipenv.
  4. Step 4: Activate the virtual environment.
  5. Step 5: Install Django in the activated virtual environment.

All Done! These are the five steps you need to take to install Django.

Let’s get into the details.

Step 1: Create a folder and name it the project name.

You first need to create a folder where your project and virtual environment will be located. Let’s use an example of a to-do website. If you’re creating a to-do website, you may want to name the folder todoapp or todosite or djangotodo. Just name it something that best explains your projects in a very few letters.

I store my Django projects in the following folder:

Documents>> SoftDev>> Projects>> Django

So what I’d do is navigate to the Django folder and create a new folder with the name of my project. You don’t really have to be as organized as this. You can simply create yours on the Desktop.

Some will prefer to do it on the command line.

Command Line (example code)

$ cd documents\softdev\projects\django
$ mkdir todoapp

If you used the command line do not close the terminal or change it for you’ll use it in the next section.

Did you create a folder in your favorable location and named it your project name? Good! Now it is time to get (cd) into that folder and create a virtual environment.

Step 2: Open your terminal and Cd (Change directory) into your project folder

We are going to create a virtual environment inside the folder you created in step 1. Since we are doing it through the command line, you first need to cd into that folder. cd stands for change directory.

Continuing from the above example. If you had already got into the direct parent of the project folder and you had not closed the terminal. simply cd into the project folder:

$ cd todoapp

If you’re not in the direct parent folder:

$ cd documents\softdev\projects\django\todoapp

A quick method is to navigate into the project folder from your file explorer and then click inside the path section and copy the path. Paste the path next to cd in the terminal.

Are you now in the project folder on your terminal? Good! It’s now time to create a virtual environment inside that folder.

Steps 3-5: Create a virtual environment, Activate It and Install Django.

This is where the steps divert. With virtualenv, you start by creating the virtual environment itself and then activate it. It’s only after then that you can install Django. On the other hand, with pipenv, Django is installed during the creation of the virtual environment. Then you can activate it.

How To Create A Virtual Environment With Virtualenv.

Below are the steps to creating a virtual environment with virtual env.

➊Make sure, on your terminal, you’re in the folder you want to create the virtual environment. The project folder. Refer to the previous step to learn how to do it.

➋In that folder, run the following command.

$ virtualenv env

The env at the end is the name of the virtual environment. Three names are usually used for virtual environments namely env, venv and .env. You can use one that suits you best. Now after the above command runs, you should see a folder inside your project folder with the name you’ve given to the virtual environment. That’s your virtual environment.

Double click the folder to open it. There should be some other folders inside. Double click the Scripts folder. Inside there, you’ll find a file called activate.bat. That file is the one that contains the code to activate the virtual environment. Now, all we have to do is to open the file via the terminal in order to activate the virtual environment.

➌Run the following command to activate the virtual environment:

$ .\env\scripts\activate.bat

The . represents ‘current folder’, in this case, it’s the project folder. env is the name of your virtual environment.

Once that command has run. There should be some brackets at the start of your terminal with the name of the virtual environment to indicate that the virtual environment is now active. Something like below.

(env) $

That’s the one thing I prefer virtualenv over pipenv. Unlike pipenv, it shows you when the virtual environment is activated. Pipenv, on the other hand, does not on the Windows operating system. This can really be problematic since it has the potential to bring mistakes.

For Mac and Linux users, pipenv is perfectly fine. But for Windows, I don’t recommend it for that reason. Anyway, I’ll show you how to use it in case you’re interested.

➍Now it is time to install Django in the activated virtual environment.

Run the following command:

$ pip install django

That’s it. After this command finishes running, Django will be installed in the virtual environment and ready to start its use. Inside env\libraries\ is where you’ll find Django and its dependencies. Take a look at what’s installed. This will install the latest Django version. Check out how to install a specific version if you want to do so.

This concludes our section on how to install Django on Windows using virtualenv. Lets get into an alternate universe of pipenv.

How To Create A Virtual Environment With Pipenv.

Although there is that given drawback about pipenv, it’s easier to use than virtualenv as you only need two commands to create, activate it, and install Django.

Follow the steps below to install Django using pipenv.

➊Make sure, on your terminal, you’re in the folder you want to create the virtual environment. The project folder. Refer to the previous step to learn how to do it.

➋Run the following command:

$ pipenv install django

This is the killer command that creates both creates the virtual environment and installs Django in it. If you look into the project folder there are two files, a Pipfile and a Pipfile.lock. Pipfile, among other dependencies, is where Django is installed. This will install the latest Django version. Check out how to install a specific version if you want to do so.

➌Activate the virtual environment using the command below.

$ pipenv shell

That does the job. Unfortunately, you won’t be able to verify if it is active or not if you’re on a Windows computer.

Bonus Tips and Tricks On How To Install Django On Windows.

How To Install Django Globally On Windows.

Installing Django globally simply means you’re installing Django for the whole system so that you won’t have to install it every time you start a new Django project. This is not a best practice but if you’re doing it for practice purposes, it should not be a big deal.

Run the following command on your Windows terminal to install Django globally. Make sure you’re not in an active virtual environment.

$ pip install django

The simplest way to check if Django is installed correctly is to just check the Django version. Run the following command to do so.

$ python -m django --version

-m represents ‘module’. That command should return the Django version that is installed and you know that you’ve installed Django correctly on Windows.

How To Install A specific version of Django.

As of the writing of this post, the latest Django version is Django 4. You may want to install a minor version of Django. Here is how to do it.

$ pip install django~=3.9.0

3.9.0 is the version of Django you want to install. This works whether you’re installing it in a virtual environment or not.

For pipenv. Do the following:

$ pipenv install django~=3.9.0

How To Uninstall Django From Windows.

If you have installed Django globally, run the following command on your Windows terminal to uninstall it.

$ pip uninstall django
Proceed (Y/n)? $ y

Did it uninstall successfully? Now verify that by running the command that checks for the Django version installed. All the ultimate command that lists out all the folders with Django:

$ pip show -f django

You should get some kind of error to show that Django is no longer on Windows.

How To Check if Python Is installed correctly On Windows.

To check if Python is installed on Windows, run the following command on your windows terminal.

$ python

If Python is installed, the terminal will print out it version and something like this after: Type "help", "copyright", "credits" or "license" for more information.

If it is not, good thing, Windows will open Microsoft Store to where you can download Python from. Follow the second Python installation method if you cannot walk yourself through. After installation, always run the above command to check if Python has now been installed.

Next Steps After Installing Django


Were you able to download and install Python, did you choose the virtual environment that is best for you, and were you able to install it on Windows, did you manage to create a virtual environment with it and ultimately install Django? If you answered yes to the questions above, congrats, you now know what it takes to install Django on Windows and how to do it the best way possible.

After installing Django on Windows, it is now time to start building your first Django project. You may need to find some guides on how to start a Django project or some best books to learn Django. Even some best Python books to brush up your python skills before you get deep into Django.

Let me know what you think about this post down in the comments section below. If you found it helpful, please share it with others that you think may need it. I’ll see you in other Coding Gear guides. Peace.

How To Install Django On Windows | 2023 Ultimate Guide.

Leave a Reply

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

Scroll to top