Django Installation
Before installing Django, ensure that your system already has a Python development environment set up. Next, let's look at how to install Django on different systems.
Installing Django on Windows
If you haven't installed the Python environment yet, you need to download the Python installer first.
Python download link: https://www.python.org/downloads/
Django download link: https://www.djangoproject.com/download/
Note: Django versions 1.6.x and above are fully compatible with Python 3.x.
Python Installation (Skip if already installed)
To install Python, simply download the python-x.x.x.msi file and keep clicking the "Next" button.
After installation, you need to set the Python environment variables. Right-click on Computer -> Properties -> Advanced -> Environment Variables -> Modify the system variable path, add the Python installation directory. This example uses C:\Python33, but you should install according to your actual situation.
Django Installation
Download the Django compressed package, unzip it, and place it in the same root directory as the Python installation. Navigate to the Django directory and execute python setup.py install
. Django will then be installed in the Python's Lib/site-packages directory.
Next, configure the environment variables by adding these directories to the system environment variables:
C:\Python33\Lib\site-packages\django;C:\Python33\Scripts.
After adding, you can use Django's django-admin.py
command to create new projects.
Checking Installation Success
Enter the following commands to check:
>>> import django
>>> django.get_version()
If the Django version number is output, the installation is correct.
Installing Django on Linux
Installation via yum
The following installation is for Centos Linux. If your Linux system is Ubuntu, use the apt-get
command instead.
By default, the Linux environment already supports Python. You can check if it is installed by typing Python
in the terminal.
Python 3.7.4 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Installing setuptools
Commands:
# Python3 installation
yum install python-setuptools
# Python2 installation
yum install python2-setuptools
After completion, you can use the easy_install
command to install Django.
easy_install django
Then, enter the following code in the Python interpreter:
[root@solar django]# python
Python 3.7.4 (default, May 15 2014, 14:49:08)
[GCC 4.8.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(3, 0, 6, 'final', 0)
We can see the Django version number output, indicating successful installation.
Installation via pip
If you haven't installed the pip tool yet, see: Python pip Installation and Usage.
sudo pip3 install Django -i https://pypi.tuna.tsinghua.edu.cn/simple
-i https://pypi.tuna.tsinghua.edu.cn/simple
specifies the Tsinghua mirror source for faster download.
Specify the Django download version (3.0.6 can be changed to the version you want):
sudo pip3 install Django==3.0.6 -i https://pypi.tuna.tsinghua.edu.cn/simple
If pip < 1.4, install as follows:
pip install https://www.djangoproject.com/download/1.11a1/tarball/
### Source Installation Method
Download the source package: [https://www.djangoproject.com/download/](https://www.djangoproject.com/download/)
Enter the following commands to install:
tar xzvf Django-X.Y.tar.gz # Unpack the downloaded package cd Django-X.Y # Enter the Django directory python setup.py install # Execute the installation command
After successful installation, Django will be located in the site-packages directory of your Python installation.
---
## Installation on Mac
### Download
Download the latest stable version from [here](https://www.djangoproject.com/download): DJango-3.x.y.tar.gz, download from the list on the right side of the page, as shown below:
Remember to download the latest official version. **x.y** represents the version number. Navigate to the folder where you downloaded the file and execute the following commands: (The default path on Mac is /Users/xxx/Downloads, where xxx is your username)
$ tar zxvf Django-3.x.y.tar.gz
You can also download the latest version from Github, the address is: [https://github.com/django/django](https://github.com/django/django):
git clone https://github.com/django/django.git
### Installation
Enter the unzipped directory:
cd Django-3.x.y sudo python setup.py install
After successful installation, the following information will be displayed:
…… Processing dependencies for Django==3.x.y Finished processing dependencies for Django==3.x.y
Then enter our site directory and create a Django project:
$ django-admin.py startproject testdj
Start the server:
cd testdj # Switch to the project we created $ python manage.py runserver …… Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. ```
The above information indicates that the project has been started, and the access address is http://127.0.0.1:8000/.