Python + Django + MySQLdb 环境安装

 本文介绍的安装环境是Linux下面,系统版本是Ubuntu。

    首先,你需要的软件:

  1.    Python, Python安装包 , 如果你的系统没有,请先安装Python。 

               检测自己的系统安装了Python了没有,在shell里面输入python,如果有则会出现下面的样式:              

    Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
           [GCC 4.4.3] on linux2
           Type "help", "copyright", "credits" or "license" for more information.
           >>>    
         Ubuntu系统是默认安装Python的。
  2. 其它的软件:MySQL,相信你去用它已经把它安装好了。如果没有安装好,问题自己解决。
  3. Django: 下载

    安装

    # tar xzvf Django-1.0.2-final.tar.gz 
    # cd Django-1.0.2-final 
    # python setup.py install
     


  4. MySQLDB的安装: 如果要在Django中使用MySQL,需要安装MySQLdb   

          安装包的下载:MySQL-python-1.2.2.tar.gz

         安装步骤:

    # tar zxf MySQL-python-1.2.2.tar.gz
    # cd MySQL-python-1.2.2
    # python setup.py install
    
    	
  5. 问题总结:
    • 没有Setuptools:下载 安装请参考文件解压后的ReadMe
    • 安装Django出现下面的错误:
       In file included from _mysql.c:29:
       pymemcompat.h:10:20: error: Python.h: No such file or directory
       _mysql.c:30:26: error: structmember.h: No such file or directory
       In file included from /usr/include/mysql/mysql.h:44,
                                from _mysql.c:40:

      这个是因为你的python-dev 包没有安装,请用 apt-get install python-dev 安装,安装了之后MySQLDB应该能够正常安装。


    • 安装测试:用Django创建一个项目使用Mysql数据库测试