Installing Django
Mac Users Note
Once Python 3 and the virtual environment are installed, the installation steps for Django are identical on both Windows and macOS.
The critical thing to remember with macOS is that system Python is version 2 and Django requires Python 3, so you must be running the Python virtual environment on macOS to run any of the code in this book.
Now we have Python installed and are running a virtual environment, installing Django is super easy, just type the command:
pip install "django>=2.2,<3"
For Django 3, the command is:
pip install "django>=3.0,<4"
If you are not familiar with the pip
command, put briefly, it’s the Python package manager and is used to install Python packages. To keep with Python programming tradition, pip
is a recursive acronym for “Pip Installs Packages”.
This will instruct pip
to install the latest version of Django 2 or Django 3 into your virtual environment. Your command output should look like this (for Django 2.2):
(env_myclub) ...\myclub_project> pip install "django>=2.2,<3.0"
Collecting django<3.0,>=2.2
Downloading .../Django-2.2.12-py3-none-any.whl (7.5MB)
|################################| 7.5MB 2.2MB/s
Collecting pytz (from django<3.0,>=2.2)
Downloading .../pytz-2020.1-py2.py3-none-any.whl (510kB)
|################################| 512kB 3.3MB/s
Collecting sqlparse (from django<3.0,>=2.2)
Downloading .../sqlparse-0.3.1-py2.py3-none-any.whl (40kB)
|################################| 40kB 2.6MB/s
Installing collected packages: pytz, sqlparse, django
Successfully installed django-2.2.12 pytz-2020.1 sqlparse-0.3.1
The Django 3 installation output is identical except for the version numbers.
To test the installation, go to your virtual environment command prompt, start the Python interactive interpreter by typing python
and hitting Enter. If the installation was successful, you should be able to import the module django
:
(env_myclub) ...\myclub_project>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.
>>> import django
>>> django.get_version()
'2.2.12' # Your version may be different.
>>> exit()
Don’t forget to exit the Python interpreter when you are done (you can also use CTRL-Z).
You can also check if Django has been installed directly from the command prompt with:
(env_myclub) ...\myclub_project>python -m django --version
2.2.12 # Your version may be different.