1.首先安装python

下载文件之后然后执行下面的脚本

#!/bin/bash

ScriptsRun='/tmp/installpython272tmp'
Python272='/usr/local/python272/'
Python272bin='/usr/local/python272/bin/python'
EzSetup='/usr/local/bin/ez_setup'
LocalScriptFile=`pwd`/$0


if [[ $(id -u) -ne 0 ||  -f $Python272bin ]]
then
   exit 1
fi


if [[ -d $Python272  ]] && [[ -f $Python272bin ]]
then
   $Python272bin  $EzSetup paramiko
   exit 1
else
   cd /tmp/
   rm -f Python-2.7.2.tgz*

   wget  $PythonSoft && tar zxf Python-2.7.2.tgz &&  cd Python-2.7.2
   ./configure  --prefix=/usr/local/python272  && make && make install
   $Python272bin  $EzSetup paramiko
fi


2.安装Django

wget https://www.djangoproject.com/download/1.6.2/tarball/
tar zxvf Django-1.6.2.tar.gz
cd Django-1.6.2
/usr/local/python272/bin/python setup.py  install

cp /usr/local/python272/bin/django-admin.py /usr/bin/

然后打开/usr/local/python272/bin/python
>>>import django
>>>django.VERSION
如果能看到版本号,表明安装成功

3.进入/data/wwwroot/python/目录新建一个工程

django-admin.py  startproject  mysite

执行/usr/local/python272/bin/python manage.py  runserver 0.0.0.0:8000

提示错误

   raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3


因为我们不用sqlite,所以我把/data/wwwroot/python/mysite/mysite/settings.py文件中的数据配置部分改为

DATABASES = {
   'default': {
       'ENGINE': 'django.db.backends.mysql',
       'NAME': '8888',
       'USER': '888',
       'PASSWORD': 'wendewei',
       'HOST':'192.168.100.88',
       'PORT':'8888',
   }
}

再次执行/usr/local/python272/bin/python manage.py  runserver 0.0.0.0:8000

提示:django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb


安装MySQL-python-1.2.3.tar.gz

tar zxvf MySQL-python-1.2.3.tar.gz && cd MySQL-python-1.2.3

/usr/local/python272/bin/python setup.py install 提示错误

   raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found


修改vi site.cfg 中mysql_config = /usr/local/mysql/bin/mysql_config


再执行 /usr/local/python272/bin/python setup.py install就可以成功安装MySQL-python


这样就可以成功启动Django了。