Installing Python
A lot of Windows applications use Python, so it may be already installed on your system. You can check this out by opening a command prompt, or running PowerShell, and typing python
at the prompt.
If Python isn’t installed you’ll get a message saying that Windows can’t find Python. If Python is installed, the python command will open the Python interactive interpreter:
C:\Users\Nigel>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
You can see in the above example that my PC is running Python 3.6.0. Django 2.2 is compatible with Python version 3.5 and later. Django 3.0 is compatible with Python version 3.6 and later. If you have an older version of Python, you must install Python 3.7 or 3.8 for the code in this book to work. If you have Python 3.5 or 3.6, I still recommend you install Python 3.8 to ensure you have the latest version installed on your machine.
Assuming Python 3 is not installed on your system, you first need to get the installer. Go to https://www.python.org/downloads/ and click the big yellow button that says “Download Python 3.8.x”.
At the time of writing, the latest version of Python is 3.8.3, but it may have been updated by the time you read this, so the numbers may be slightly different. Once you have downloaded the Python installer, go to your downloads folder and double click the file python-3.x.x.msi
to run the installer. The installation process is the same as any other Windows program, so if you have installed software before, there should be no problem here; however, there is one essential customization you must make.
By default, the Python executable is not added to the Windows PATH. For Django to work correctly, Python must be listed in the PATH statement. Fortunately, this is easy to rectify—when the Python installer screen opens, make sure “Add Python 3.8 to PATH” is checked before installing (Figure 2-1).
Do Not Forget This Step!
It will solve most problems that arise from the incorrect mapping of pythonpath (an important variable for Python installations) in Windows.
Figure 2.1: Check the “Add Python 3.8 to PATH” box before installing.
Once Python is installed, restart Windows and then type python
at the command prompt. You should see something like this:
C:\Users\nigel> python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>