以前出于兴趣,学过一点python,但是没有真正使用过,最近正好有一个python相关的项目,趁机想多多学点。python的确是一门不错的语言,python可以用于几乎所有的编程领域,也就是说,熟练掌握了python,你就可以不用再为切换语言开发而烦恼。这里推荐我用到的两本书《The Django book》和《Django Web 开发指南》,指南有句经验比较不错,如果你哪里配置的不对,不要纠结太久,重新来做一遍效果可能会更好。
本文主要介绍环境搭建
1 安装python,本文用的是python2.7,本人用的win7 64位系统,但是安装的32位的python2.72、安装Django 1.6.7 (本人尝试过用最新版本,和书上有出入,查找起来有些麻烦,故放弃了)
具体步骤:
1)下载压缩包,并解压
2) 运行cmd ,进入解压后的目录(setup.py所在的目录),
执行: python setup.py install
安装完成后,在python下输入
import django
django.VERSION
如果没有出错,会显示django的版本号
3、 安装mysql、和Mysql插件
mysql安装这里就不介绍了
支持mysql的插件的下载地址http://www.codegood.com/downloads
本人下载的是MySQL-python-1.2.3.win32-py2.7.exe(要与python的版本一致,即都是32位的)
安装过程也不是一帆风顺的,提示
“Python version 2.7 required, which was not found in the registry”
此处摘抄别人的python脚本,
这里命名为register.py
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html
import sys
from _winreg import *
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)
def RegisterPy():
try:
reg = OpenKey(HKEY_CURRENT_USER, regpath)
except EnvironmentError as e:
try:
reg = CreateKey(HKEY_CURRENT_USER, regpath)
SetValue(reg, installkey, REG_SZ, installpath)
SetValue(reg, pythonkey, REG_SZ, pythonpath)
CloseKey(reg)
except:
print "*** Unable to register!"
return
print "--- Python", version, "is now registered!"
return
if (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)
print "=== Python", version, "is already registered!"
return
CloseKey(reg)
print "*** Unable to register!"
print "*** You probably have another Python installation!"
if __name__ == "__main__":
RegisterPy()
在cmd下运行python register.py,会显示“python 2.7 is already registered”
这时再进行安装MySQL-python-1.2.3.win32-py2.7.exe,顺利完成。
测试,在python下 输入 import MySQLdb, 没有报错就安装成功了
下一篇,介绍django开发基本网页和使用mysql