Quick install guide
Before you can learn Django, you'll need to install it first. Here is a simple and minimal installation of Django that'll work through the introduction.
Install Python
Django is a Python Web framework, so Python installation is required.
You may need to know What Python version can be used with Django?.
To check Python version, you can just simply type python
or python3
from your shell.
Database
Python includes a lightweight database called SQLite. If you want to use a "larger" database, such as MySQL or Oracle, then you need to install them.
Install Django
There are three easy ways to install Django:
- Install an official release
- Install a version of Django provided by the operating system distribution
- Install the latest development version
Installing an official release with pip
This is the recommended way to install Django.
- Install pip.
- Take a look at virtualenv and virtualenvwrapper
pip install Django
Install pip
This step can be upgrade pip because pip is already installed with the python installation or Virtual Environment.
To upgrade pip, just run:
pip install -U pip
# or
pip install --upgrade pp
And here is a quick start for pip.
Virtualenv and Virtualenvwrapper
These tools provide isolated Python environments, which are more practical than installing packages systemwide.
Install virtualenv
Install virtualenv can be easily using:
pip install virtualenv
Usage
Virtualenv has one basic command:
$ virtualenv ENV
This command create a new virtual environment and ENV
is the directory to place the new virtual environment.
-
ENV/lib/
andENV/include/
containing supporting library files for python environment. Packages installed in this environment will live underENV/lib/pythonX.X/site-packages/
. -
ENV/bin/
includes executables live. If you want your python script using a virtualenv's python, you can add#! /path/to/ENV/bin/python
to your script. - pip and setuptools are installed.
Activate script
In directory /ENV/bin/
, run:
$ source activate
This will change the $PATH
so its first entry is the virtualenv's bin/
directory.
This also modify the shell prompt to indicate which environment is currently active.
To undo these changes, just run:
$ deactivate
Removing an Environment
To remove a virtual environment, just deactivate it and delete the environment folder.
Useful options
--system-site-packages
makes the virtual environment to inherit packages from global site-packages directory (i.e. /usr/lib/python2.7/site-packages
)
--python=/path/to/python
use the specific python version.
virtualenvwrapper
Virtualenvwrapper is a tool to organize all of your virtual environments in one place.
Installation
$ pip install virtualenvwrapper
The default work on home is ~/.virtualenvs/
create env
source /usr/local/bin/virtualenvwrapper.sh
# create new env
mkvirtualenv env1
# delete env
rmvirtualenv env1
# change to env
workon env1
Install the development version
git clone https://github.com/django/django.git
pip install -e django/
网友评论