I have to use Python and Django for our application. So, I have two versions of Python, 2.6 and 2.7. Now I have installed Django. I could run the sample application for testing Django succesfuly. But how do I make sure whether Django uses the 2.6 or 2.7 version and what version of modules Django uses?

- 22,221
- 10
- 124
- 129

- 7,657
- 3
- 20
- 18
-
101Shortest way - `python3 -m django --version` – Aniket Thakur Jan 07 '18 at 04:53
-
12In my installation python3 is not recognized. This works: python -m django --version – Antti A Dec 25 '18 at 14:10
-
1I believe since a somewhat old Python version is preinstalled on MacOS systems, a suffix of "3" is required on "python" command to avoid confusions from the OS side on which version to use. This isn't required on Windows systems so @AnttiA 's solution works just fine. – Dasun Nirmitha Sep 13 '20 at 10:53
-
8another shortest way is `django-admin --version` – Trigremm Oct 20 '20 at 17:35
-
The suggested commands show your installed django version, not the code version. Check the *requirements.txt* `cat src/requirements.txt | grep "Django=="` or in your application's settings.py file, on the fifth line you'll see something like `Generated by 'django-admin startproject' using Django x.x.x` (for the user-specific question, the accepted answers are the way, but I found that this could also be useful). – Rodrigo May 05 '23 at 19:58
32 Answers
Django 1.5 supports Python 2.6.5 and later.
If you're under Linux and want to check the Python version you're using, run python -V
from the command line.
If you want to check the Django version, open a Python console and type
>>> import django
>>> django.VERSION
(2, 0, 0, 'final', 0)

- 25,987
- 18
- 90
- 141
-
2Just dive into env before you check the version, otherwise no module named django. – EngineSense Feb 05 '20 at 05:37
-
This says - `AttributeError: module 'django' has no attribute 'VERSION'` – Tanmay Bairagi Apr 27 '22 at 07:16
Basically the same as bcoughlan's answer, but here it is as an executable command:
$ python -c "import django; print(django.get_version())"
2.0

- 455
- 1
- 6
- 19

- 4,769
- 1
- 15
- 17
-
Combining Brady Emerson and bcoughlan: ```python -c "import django; print(django.VERSION)"``` returns ```(1, 8, 5, 'final', 0)``` – David Gleba Mar 24 '18 at 15:36
-
You should do `python -c "import django; print(django.__version__)"` instead. It also returns `'2.2.4'` (it's [just a call to `get_version()`](https://github.com/django/django/blob/master/django/__init__.py#L5)) and is the standard followed by most other libraries because it's [defined in PEP 8](https://www.python.org/dev/peps/pep-0008/#module-level-dunder-names). It works since [Django 1.8](https://github.com/django/django/blob/1.8/django/__init__.py#L5) – Boris Verkhovskiy Aug 10 '19 at 00:55
If you have installed the application:
$ django-admin --version
3.2.6
-
As May 2018 (the date I've tested this answer again), it shows version as 1.11.5 despite I've installed 2.0.1. But `>> django.VERSION` in python shell displays the right version – Ghasem May 09 '18 at 08:08
-
2this worked for me: ubuntu 18.04, virtualenv with P 3.6 and Django 2.2 – Carmine Tambascia Apr 03 '19 at 15:28
-
For older versions it is `django-admin.py --version`. Depending on how you've done your python installation, you may even need `python django-admin.py --version`. – theQuestionMan Sep 14 '20 at 04:51
-
This works for me in 2022, ubuntu 20.02, virtualenv with Python 3.8 and Django 4.0.2 – Dr Phil Jul 19 '22 at 15:08
-
this just shows you the django-admin version. it's `python3 -c "import django; print(django.get_version())"` that will give you the actual django version installed – bluebuddah Dec 09 '22 at 18:16
Go to your Django project home directory and do:
./manage.py --version

- 30,738
- 21
- 105
- 131

- 3,018
- 6
- 25
- 36
-
I like this one as we as Django devs often use the manage.py functionalities. You can also use 'python manage.py version' (no need for --) – Jim B Dec 02 '21 at 11:53
>>> import django
>>> print(django.get_version())
1.6.1
I am using the IDLE (Python GUI).

- 22,409
- 6
- 71
- 81

- 584
- 4
- 4
If you have pip, you can also do a
pip freezeand it will show your all component version including Django .
You can pipe it through grep to get just the Django version. That is,
josh@villaroyale:~/code/djangosite$ pip freeze | grep Django
Django==1.4.3

- 526
- 10
- 21

- 925
- 11
- 13
As you say you have two versions of Python, I assume they are in different virtual environments (e.g. venv) or perhaps Conda environments.
When you installed Django, it was likely in only one environment. It is possible that you have two different versions of Django, one for each version of python.
In from a Unix/Mac terminal, you can check your Python version as follows:
$ python --version
If you want to know the source:
$ which python
And to check the version of Django:
$ python -m django --version

- 30,738
- 21
- 105
- 131

- 105,104
- 32
- 201
- 196
For Python:
import sys
sys.version
For Django (as mentioned by others here):
import django
django.get_version()
The potential problem with simply checking the version, is that versions get upgraded and so the code can go out of date. You want to make sure that '1.7' < '1.7.1' < '1.7.5' < '1.7.10'. A normal string comparison would fail in the last comparison:
>>> '1.7.5' < '1.7.10'
False
The solution is to use StrictVersion from distutils.
>>> from distutils.version import StrictVersion
>>> StrictVersion('1.7.5') < StrictVersion('1.7.10')
True

- 1
- 1

- 1,708
- 1
- 19
- 31
-
4What about using `django.VERSION`, which already comes as a tuple? I'm pretty sure doing `django.VERSION >= (1, 8)` will always work as intended. – Flimm Dec 14 '17 at 18:26
There are various ways to get the Django version. You can use any one of the following given below according to your requirements.
Note: If you are working in a virtual environment then please load your python environment
Terminal Commands
python -m django --version
django-admin --version
ordjango-admin.py version
./manage.py --version
orpython manage.py --version
pip freeze | grep Django
python -c "import django; print(django.get_version())"
python manage.py runserver --version
Django Shell Commands
import django django.get_version()
ORdjango.VERSION
from django.utils import version version.get_version()
ORversion.get_complete_version()
import pkg_resources pkg_resources.get_distribution('django').version
(Feel free to modify this answer, if you have some kind of correction or you want to add more related information.)

- 1
- 1

- 1,165
- 15
- 20
Simply type python -m django --version
or type pip freeze
to see all the versions of installed modules including Django.
-
2no reason for this to be downvoted at all, it is one of the most concise answers. – tfantina Apr 21 '20 at 13:34
django-admin --version
python manage.py --version
pip freeze | grep django

- 620
- 7
- 15
-
-
-
I needed to make the d in Django capital for grep to find it. – Anthony Petrillo Mar 23 '22 at 13:54
-
The first command and the second return two different version numbers for me. – Sean Jun 14 '22 at 15:35
For checking using a Python shell, do the following.
>>>from django import get_version
>>> get_version()
If you wish to do it in Unix/Linux shell with a single line, then do
python -c 'import django; print(django.get_version())'
Once you have developed an application, then you can check version directly using the following.
python manage.py runserver --version

- 30,738
- 21
- 105
- 131

- 57,311
- 13
- 161
- 150
Official Documentation
First:
python -m django --version
Second:
import django
print(django.get_version())

- 2,609
- 1
- 29
- 41

- 129
- 1
- 7
Django version or any other package version
Open the terminal or command prompt
Type
pip show django
or
pip3 show django
You can find any package version...
Example:
pip show tensorflow
pip show numpy
etc....

- 30,738
- 21
- 105
- 131

- 381
- 5
- 5
-
I like the simplicity of this answer best. `pip freeze` shows a ton of extra crap if you've pip'd in a bunch of packages. – DukeSilver Mar 11 '20 at 02:56
Run pip list
in a Linux terminal and find Django and its version in the list:
Run pip freeze
on cmd on Windows.

- 30,738
- 21
- 105
- 131

- 319
- 4
- 11
Django will use the version of Python specified by the PYTHONPATH environment variable. You can use echo $PYTHONPATH
in a shell to determine which version will be used.
The module versions used by Django will be the module versions installed under the version of Python specified by PYTHONPATH.

- 28,485
- 8
- 71
- 90
There is an undocumented utils
versions module in Django:
https://github.com/django/django/blob/master/django/utils/version.py
With that, you can get the normal version as a string or a detailed version tuple:
>>> from django.utils import version
>>> version.get_version()
... 1.9
>>> version.get_complete_version()
... (1, 9, 0, 'final', 0)

- 30,738
- 21
- 105
- 131

- 3,985
- 38
- 51
You can do it without Python too. Just type this in your Django directory:
cat __init__.py | grep VERSION
And you will get something like:
VERSION = (1, 5, 5, 'final', 0)

- 489
- 3
- 15
-
1This is great when you don't want to activate the virtual env just to get a value, or you're using something like AWS Elastic Beanstalk and can't activate the virtual env. – rjferguson Jan 14 '15 at 08:06
-
1@rjferguson you dont need to activate your env to do a `pip freeze` / `python -c "import
; – Javier Buzzi Dec 01 '15 at 16:34.VERSION"`. You can simply reference it: `/path/to/env/bin/python -c " "` or if you want to install/use pip, same thing: `/path/to/env/bin/pip freeze`. I use this all the time, specially when im logged in as a root and all of my application code runs as `www-data` i do: `sudo su www-data -c "/path/to/env/bin/pip install "` and not even blink. (i know this is almost 2 years later, and you probably know about it now -- this is more for the next guy) -
The most pythonic way I've seen to get the version of any package:
>>> import pkg_resources;
>>> pkg_resources.get_distribution('django').version
'1.8.4'
This ties directly into setup.py: https://github.com/django/django/blob/master/setup.py#L37
Also there is distutils
to compare the version:
>>> from distutils.version import LooseVersion, StrictVersion
>>> LooseVersion("2.3.1") < LooseVersion("10.1.2")
True
>>> StrictVersion("2.3.1") < StrictVersion("10.1.2")
True
>>> StrictVersion("2.3.1") > StrictVersion("10.1.2")
False
As for getting the python
version, I agree with James Bradbury:
>>> import sys
>>> sys.version
'3.4.3 (default, Jul 13 2015, 12:18:23) \n[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]'
Tying it all together:
>>> StrictVersion((sys.version.split(' ')[0])) > StrictVersion('2.6')
True

- 6,296
- 36
- 50
Python version supported by Django version
Django version Python versions
----------------------------------------
1.0 2.3, 2.4, 2.5, 2.6
1.1 2.3, 2.4, 2.5, 2.6
1.2 2.4, 2.5, 2.6, 2.7
1.3 2.4, 2.5, 2.6, 2.7
1.4 2.5, 2.6, 2.7
1.5 2.6.5, 2.7 and 3.2.3, 3.3 (experimental)
1.6 2.6.5, 2.7 and 3.2.3, 3.3
1.11 2.7, 3.4, 3.5, 3.6, 3.7 (added in 1.11.17)
2.0 3.4, 3.5, 3.6, 3.7
2.1, 2.2 3.5, 3.6, 3.7
To verify that Django can be seen by Python, type python
from your shell. Then at the Python prompt, try to import Django:
>>> import django
>>> print(django.get_version())
2.1
>>> django.VERSION
(2, 1, 4, 'final', 0)

- 30,738
- 21
- 105
- 131

- 6,098
- 5
- 32
- 50
If you want to make Django version comparison, you could use django-nine
(pip install django-nine). For example, if Django version installed in your environment is 1.7.4, then the following would be true.
from nine import versions
versions.DJANGO_1_7 # True
versions.DJANGO_LTE_1_7 # True
versions.DJANGO_GTE_1_7 # True
versions.DJANGO_GTE_1_8 # False
versions.DJANGO_GTE_1_4 # True
versions.DJANGO_LTE_1_6 # False

- 12,746
- 4
- 52
- 44
You can get django version by running the following command in a shell prompt
python -m django --version
If Django is installed, you should see the version otherwise you’ll get an error telling “No module named django”.

- 4,454
- 3
- 27
- 19
Type the following command in Python shell
import django
django.get_version()

- 143
- 4
you can import django and then type print statement as given below to know the version of django i.e. installed on your system:
>>> import django
>>> print(django.get_version())
2.1

- 608
- 9
- 4
Open your CMD or Terminal and run any of the following commands
django-admin --version
or
python3 -m django --version
or
pip freeze

- 37
- 7
From your code, you can get the version of Django by using any of the two below.
import django
print(django.__version__)
# '3.1.5'
print(django.VERSION)
# (3, 1, 5, 'final', 0)
or from your terminal, you can run
django-admin --version

- 960
- 1
- 8
- 12
It's very simple open the CLI(command line or any IDE) wherever you installed python and Django just type,
django-admin --version
see here I have installed the latest Python and Django in my system and the result is shown in fig.

- 235
- 2
- 3
There are two more methods to get the Version (of Django and other packages). Both of them need a version variable for the package to get the version. According to PEP-396 the __version__variable should be set for every Python module.
Method 1 - Get version from filesystem
With that in mind, you know how to get the version for almost every Django/Python package. Look inside the __init__.py of the package root. So if you are a fast at navigating through the filesystem, this can be a very universal way of getting the Version of any package inside your site-package (virtual environment).
Method 2 - Django Debug Toolbar
There is a very helpful tool that is called django debug toolbar. If you use it (very recommendable for Django development) you can list the versions of all apps that have a package.__version__.

- 1,959
- 12
- 27
These commands below get Django version:
django-admin --version
python manage.py --version
But, these commands below get error:
django-admin -v
python manage.py -v

- 22,221
- 10
- 124
- 129