Uninstall
Using pip
Install the python-pip
:
sudo apt-get install python-pip
Remove django
using pip
:
sudo pip uninstall Django
Uninstall the python-pip
:
sudo apt-get remove python-pip
Using the shell
Python
:
Use the shell Python
to discover the path of Django
:
>>> import django >>> django <module 'django' from '/usr/local/lib/python2.7/dist-packages/django/__init__.pyc'>
Then remove manually:
sudo rm -rf /usr/local/lib/python2.7/dist-packages/django/
Install
There are several different ways to install Django
, depending on your needs and how you want to set up your development environment. These have different advantages and one method can lend itself better to your specific situation than others.
Some of the different methods are below:
Install from packages: The official Ubuntu repositories contain packages Django
which can be installed easily with conventional apt
package manager. This is very simple, but not as flexible as some other methods. In addition, the version contained in the repositories may lag behind the official versions available from the project.
Across pip
: The pip
tool is a package manager for packages Python
. If you install pip
, you can easily install Django
at system level to be used by any user. This must always contain the latest stable version. Even so, global facilities are inherently less flexible.
Install through pip
in a Virtualenv
: The Python
virtualenv
package allows you to create independent environments for multiple projects. Using this technology, you can install the Django
in a project directory without affecting the larger system. This allows you to provide customizations and packages per project easily. The virtual environments add some slight mental overload and process compared to globally accessible installation, but provide the greatest flexibility.
Install through git
: If you want to install the latest development version instead of the stable version, you will have to purchase the code from git repo
. This is required to get the latest features /
corrections and can be done at global or local level. Development versions do not have the same guarantees of stability, however.
From packages
If you want to install Django
using the repositories of Ubuntu
, the process is very simple. First, update your local list of packages with apt
, then install the python-django
bundle:
sudo apt-get update sudo apt-get install python-django
You can test whether the installation was successful by writing:
django-admin --version
Through the pip
If you want to install the latest version of Django
overall, the best option is to use pip
, the package manager Python
. First, we need to install the pip
package manager.
sudo apt-get update
Now you can install pip
:
sudo apt-get install python-pip // Python 2
sudo apt-get install python3-pip // Python 3
Now that you have pip
, can easily install Django
.
sudo pip install django // Python 2
sudo pip3 install django // Python 3
You can check whether the installation was successful by writing:
django-admin --version
Through pip
in a Virtualenv
Let’s start with installing Pip from the Ubuntu repositories.
sudo apt-get update
sudo apt-get install python-pip // Python 2
sudo apt-get install python3-pip // Python 3
With the pip
installed, you can use it to install the virtualenv
bundle.
sudo pip install virtualenv // Python 2
sudo pip3 install virtualenv // Python 2
Now, whenever you start a new project, you can create a virtual environment for it. Start creating and moving in a new project directory:
mkdir ~/ newproject cd ~/ newproject
Now create a virtual environment within the project directory by writing:
virtualenv newenv
This will install a standalone version of Python
, as well as pip
, in an isolated directory structure within your project directory. Here our virtual environment is called newenv
, You can choose that name. A directory will be created with the name you choose, and will perform the file hierarchy where your packages will be installed.
To install packages in the isolated environment, you must activate it by typing:
source newenv /bin/activate
Your prompt should change to reflect that you are now in your virtual environment. It will look like ( newenv )username@hostname:~/newproject$
.
In your new environment, you can use the pip
to install Django
. Regardless of whether you are using Python version 2 or 3, it should be called only pip
when you are in your virtual environment. Also note that you do not need to use sudo
since you are installing locally:
pip install django
You can check the installation by typing:
django-admin --version
To leave your virtual environment, you need to issue the deactivate
control of any place in the system:
deactivate
Your prompt should revert to the conventional screen. When you want to work on your project again, you should reactivate your virtual environment by moving back to the project directory and activating:
cd ~/ newproject source newenv /bin/activate
Across git
If you need a development version of Django
, you will have to download and install Django
from their git
repository. To do this, you will need to install the git
in your system with apt
.
sudo apt-get update
To install git:
sudo apt-get install git python-pip // Python 2
sudo apt-get install git python3-pip // Python 3
After having git
, you can clone the repository Django
:
git clone git://github.com/django/django ~/django-dev
Once the repository is cloned, you can install it using pip
. We’re gonna use the -e
option to install in "editable" mode, which is required during version control installation.
sudo pip install -e ~/django-dev // Python 2
sudo pip3 install -e ~/django-dev // Python 3
You can check whether the installation was successful:
django-admin --version
English version of this installation tutorial.
Make a tour by stackoverflow, know some of the rules and good practices.
– Marco Giovanni