Updates on Django Installation
Being a Python Web framework, Django requires Python. Unless you’d like to work with a large database engine such as PostgreSQL,
MySQL, or Oracle, Python includes a lightweight database called
SQLite so you won’t need to set up a database immediately.
Remove any old versions of Django
If you are upgrading your installation of Django from a previous version, you will need to uninstall the old Django version before installing the new version.
If you installed Django using
pip or
easy_install previously, installing with
pip or
easy_install again will automatically take care of the old version, so you don’t need to do it yourself.
If you previously installed Django using
python setup.py install, uninstalling is as simple as deleting the
django directory from your Python
site-packages. To find the directory you need to remove, you can run the following at your shell prompt (not the interactive Python prompt):
$ python -c "import django; print(django.__path__)"
What Python version can you use with Django?
Before installing or upgrading Django, you should check
What Python version can you use with which Django version:
https://docs.google.com/document/d/19ed ... sp=sharing
Install the Django code
Installation instructions are slightly different depending on whether you’re installing a distribution-specific package, downloading the latest official release, or fetching the latest development version.
Installing an official release with pip
The recommended way to install django is using
pip. Here are steps to follow:
- Install pip. The easiest is to use the standalone pip installer. If your distribution already has pip installed, you might need to update it if it’s outdated. If it’s outdated, you’ll know because installation won’t work.
- Take a look at virtualenv and virtualenvwrapper. These tools provide isolated Python environments, which are more practical than installing packages systemwide. They also allow installing packages without administrator privileges.
- After you’ve created and activated a virtual environment, enter the command
at the shell prompt.
Practical Example: Make virtualenv and install Django 2.0 in Python 3.4.3 under Ubuntu-Linux
#Install virtualenv:
pip install virtualenv
#Make directory to keep all separate environments in one place and move to it:
$mkdir Environments
$cd Environments
#Make the first Django virtualenv
virtualenv Django_project --python=python3.4 #Note here, we specify the Python version
virtualenv Django_project #This is the default virtualenv for Python 2
#Activate the virtualenv created
source Django_project/bin/activate
#Or
. Django_project/bin/activate
#Try which pip (pip3) or which python3.4 to see if they are inside the newly created virtual environment:
#If the package is inside the virtualenv, for example pip3, "which pip3" should show a path such as:
.../Environments/Django_project/bin/pip3
#Install Django version 2.0
pip3 install Django==2.0
Important!
We create virtual environments because we do not want to install Django and its dependencies with
sudo. The reason we avoid using
sudo is that sudo will install packages/libraries systemwide - this usually causes issues, especially, when you have more than one project each depending on specific versions of libraries/packages.
$
virtualenv yourvirtualenv --python=python3.6
#Work on your virtualenv
$
. yourvirtualenv/bin/activate
$
pip3 install -r requirements.txt
The above commands get you set up by making your virtualenv 'yourvirtualenv' and specifying which Python version you want to use (in this case Python 3.6). You then activate the environment and finally install your requirements file.
Installing a distribution-specific package
Check the
distribution specific notes to see if your platform/distribution provides official Django packages/installers. Distribution-provided packages will typically allow for automatic installation of dependencies and easy upgrade paths; however, these packages will rarely contain the latest release of Django.
Tracking Django development
! | Message from: Developers |
If you decide to use the latest development version of Django, you’ll want to pay close attention to the development timeline, and you’ll want to keep an eye on the release notes for the upcoming release. This will help you stay on top of any new features you might want to use, as well as any changes you’ll need to make to your code when updating your copy of Django. (For stable releases, any necessary changes are documented in the release notes.) |
If you’d like to be able to update your Django code occasionally with the latest bug fixes and improvements, follow these instructions:
- Make sure that you have Git installed and that you can run its commands from a shell. (Enter git help at a shell prompt to test this.)
- Check out Django’s main development branch like this:
Code: Select all
$ git clone https://github.com/django/django.git
This will create a directory django in your current directory.
Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is to use virtualenv, virtualenvwrapper, and pip.
After setting up and activating the virtualenv, run the following command:
This will make Django’s code importable, and will also make the
django-admin utility command available. In other words, you’re all set!
When you want to update your copy of the Django source code, just run the command
git pull from within the
django directory. When you do this, Git will automatically download any changes.