Posted by Marta on January 25, 2021 Viewed 1773 times
There are different ways you can check the Django your version. In this article, I will share a couple of them. I will also share how you can upgrade and downgrade the Django version, uninstall Django, something you might do if you are running into problems and decide to uninstall it and install Django again. […]
There are different ways you can check the Django your version. In this article, I will share a couple of them. I will also share how you can upgrade and downgrade the Django version, uninstall Django, something you might do if you are running into problems and decide to uninstall it and install Django again.
Finding the Django version can be useful if you want to make sure your python and Django versions are compatible. I have also included a section to show how to find the python version that you are using.
Find your Django version can also be useful to make sure a feature you are using is supported that the Django version is installed.
The way you check your Django version depends on if you installed Django on your base python installation or you installed the module in a virtual environment. Let’s see first how to check your version on the base python installation.
To achieve this, open the idle terminal and type the following:
import django django.get_version()
Output(you should get something similar):
You could also use the following code, that will return the same results, but slightly different format:
import django django.VERSION
(3, 0, 8, 'final', 0)
The above commands will work in Mac and also in Windows.
You can also check the version by using pip. Run the following command on your terminal:
>> pip3 freeze
Django==3.0.8 # Django version docutils==0.14 dominate==2.5.1 Flask==1.1.1 Flask-Bootstrap==22.214.171.124 importlib-metadata==1.6.0
If Django is in your Python installation, it will be listed along with any other module installed.
If you were working within a virtual environment when you installed the Django module, Django is only available within the virtual environment. It won’t be installed in the base Python installation.
Therefore, if you want to check the version, you need to activate the virtual environment. Run the following command to check the version installed in your virtualenv.
>> cd <replace_with_parent_of_your_virtualenv_directory> >> source venv/bin/activate >> python -c "import django; print(django.get_version())"
You can also run this in pycharm, from the terminal tab.
In case you need to deactivate the virtual environment, you can do so by running the following command from your terminal:
When you installed Django, some admin scripts come with the installation. These commands help you manage apps, manage database patches, and you can also find the Django version in use. There are two possible commands; both achieve the same thing.
>> django-admin.py version
>> python manage.py --version
All of these commands are doing the same thing, finding the Django version installed.
You can upgrade Django and any module installed using the
pip command. You can run the following command from your terminal or the Pycharm terminal. As before, if you are working on a virtual environment, make sure you activate the environment before running the command:
>> pip install --upgrade django
The command above will upgrade to the latest available version.
In case you would like to downgrade, you can do this via pip as well, using the following command:
>> pip install -v Django==3.0.5 #Replace with your version
You can find a list of all the available Django version here.
As before, in case you are working within a virtual environment, make sure it is activated. Or, if you have several python versions installed on your computer, make sure your pip command you are using belongs to the python installation you are using to run your python program. You can check this by running the following Linux command from your terminal.
>> which pip
The output should be the same folder as the folder where your python version is installed.
You might need to uninstall Django if you decide to use another web framework. Or if you are getting running into errors and you want to get a clean Django installation. You can uninstall the Django module via pip, just running the following command:
>> pip uninstall django
Run the following command to check the Django module was uninstalled:
>> pip freeze
If the module was uninstalled correctly, the Django module should not appear within the module list.
If you just uninstalled Django, probably a reminder of how to install back comes handy. Not that is something difficult to remember, though. You can install Django using
pip. Here is the command:
>> pip install django
As before, if you are working in a virtual environment, remember to activate the virtual environment before running this command.
If you have several python installations in your machine, make sure the
pip command you are using belongs to the correct python installation.
To give you a concrete example of this. I have two python versions installed on my laptop. Python 2 which is pre-installed in Mac and python 3. You can run the following commands to check this:
>> python --version Python 2.7.15 >> python3 --version Python 3.7.2 >> which python /usr/local/bin/python >> which python3 /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
That means the
pip command you used to install the Django module should belong to the same folder as the python version you are using to run
python. To check that, you can run the following command:
>> which pip /Library/Frameworks/Python.framework/Versions/3.7/bin/pip >> which pip3 /Library/Frameworks/Python.framework/Versions/3.7/bin/pip3
The above output indicates that when I run
pip install django, it will install the module on the python version 3 installation. In other words, the Django module is only available for version3, not for the pre-installed version 2.
Here are the commands you can run to double-check this.
>> python -c "import django; print(django.get_version())" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named django >> python3 -c "import django; print(django.get_version())" 3.0.8
The first command points to version 2, so I get an error when importing the Django module. However, when you use the
python3 command, the command works without errors. Keep this in mind, especially if you are a mac. This problem comes up very often.
As mentioned in the previous section, you can check the python version, just running the following command in your terminal:
>> python --version
>> python3 --version
In summary, there are several ways to find the Django version you are using. All of them achieve the same thing. So choose the more convenient one based on your development environment setup. I hope this article was useful, and thank you so much for reading and supporting this blog!
Steady pace book with lots of worked examples. Starting with the basics, and moving to projects, data visualisation, and web applications
Unique lay-out and teaching programming style helping new concepts stick in your memory
Great guide for those who want to improve their skills when writing python code. Easy to understand. Many practical examples
Perfect Boook for anyone who has an alright knowledge of Java and wants to take it to the next level.
Excellent read for anyone who already know how to program and want to learn Best Practices
Perfect book for anyone transitioning into the mid/mid-senior developer level
Great book and probably the best way to practice for interview. Some really good information on how to perform an interview. Code Example in Java