Window下配置python2.7+Django
2016-09-12 00:39
393 查看
今天因为某个项目需要在自己的电脑上配置Django服务器做测试用在安装过程中遇到了很多问题,我在这里做一个记录和分享
- 尽量不要使用.2.7.5等非通用的版本,实测部分版本下库文件本身有bug,无法运行django
直接运行安装程序即可
安装完毕后需要将
C:\Python27\
C:\Python27\Scripts\
这两个路径添加到环境变量的PATH变量中
python setup.py install
这条命令,这条命令依赖setuptools.py
直接google/百度可以得到一个安装脚本,本地新建一个get-setuptools.py文件,使用python get-setuptools.py命令 执行脚本就可以完成晚装
在官网下载安装包,解压过后在解压文件的根目录下使用
python setup.py install
命令执行安装过程。
python -m pip install django==1.9.5
(使用python 指定pip 模块 安装 版本号为1.9.5的django,这个命令很简明,可以适用其他通用库的安装)
*注意在安装中可能遇到找不到python27根目录的情况,这可能是因为你是64位的机器缺采用了32位的安装包,https://pypi.python.org/pypi/pip#downloads 这个网址中可以下载对应安装包
1. 找到路径\Lib\site-packages
2. 路径下新建文件 sitecustomize.py ,文件内容为:
import sys
reload(sys)
sys.setdefaultencoding(‘utf-8’)
参见http://blog.csdn.net/a542551042/article/details/48676031
To fix the problem replace this (about line 56 in python\Lib\fuctools.py):
convert = {
‘lt‘: [(‘gt‘, lambda self, other: other < self),
(‘le‘, lambda self, other: not other < self),
(‘ge‘, lambda self, other: not self < other)],
‘le‘: [(‘ge‘, lambda self, other: other <= self),
(‘lt‘, lambda self, other: not other <= self),
(‘gt‘, lambda self, other: not self <= other)],
‘gt‘: [(‘lt‘, lambda self, other: other > self),
(‘ge‘, lambda self, other: not other > self),
(‘le‘, lambda self, other: not self > other)],
‘ge‘: [(‘le‘, lambda self, other: other >= self),
(‘gt‘, lambda self, other: not other >= self),
(‘lt‘, lambda self, other: not self >= other)]
}
to that:
convert = {
‘lt‘: [(‘gt‘, lambda self, other: not (self < other or self == other)),
(‘le‘, lambda self, other: self < other or self == other),
(‘ge‘, lambda self, other: not self < other)],
‘le‘: [(‘ge‘, lambda self, other: not self <= other or self == other),
(‘lt‘, lambda self, other: self <= other and not self == other),
(‘gt‘, lambda self, other: not self <= other)],
‘gt‘: [(‘lt‘, lambda self, other: not (self > other or self == other)),
(‘ge‘, lambda self, other: self > other or self == other),
(‘le‘, lambda self, other: not self > other)],
‘ge‘: [(‘le‘, lambda self, other: (not self >= other) or self == other),
(‘gt‘, lambda self, other: self >= other and not self == other),
(‘lt‘, lambda self, other: not self >= other)]
}
参见http://stackoverflow.com/questions/16259729/django-python-manage-py-runserver-gives-runtimeerror-maximum-recursion-depth-e
参见http://stackoverflow.com/questions/22532743/cant-import-patterns-in-django
目标配置
安装项 | 功能 |
---|---|
python2.7 | 代码运行环境 |
Django 1.9.5 | 构建服务器 |
pip | 安装python包文件 |
setuptools | 安装过程中需要 |
MySQLdb | python连接数据库的库 |
过程
安装python
从python官网下载 2.7.12 (2.7中最新的子版本)- 尽量不要使用.2.7.5等非通用的版本,实测部分版本下库文件本身有bug,无法运行django
直接运行安装程序即可
安装完毕后需要将
C:\Python27\
C:\Python27\Scripts\
这两个路径添加到环境变量的PATH变量中
安装 setuptools
在我们安装库的时候经常会使用python setup.py install
这条命令,这条命令依赖setuptools.py
直接google/百度可以得到一个安装脚本,本地新建一个get-setuptools.py文件,使用python get-setuptools.py命令 执行脚本就可以完成晚装
安装Pip
pip是和maven wget等工具等效的工具,在云端有一个仓库,我们通过pip模块与仓库交互,实现python库文件的安装删除与版本管理。在官网下载安装包,解压过后在解压文件的根目录下使用
python setup.py install
命令执行安装过程。
安装Django
在命令行中执行python -m pip install django==1.9.5
(使用python 指定pip 模块 安装 版本号为1.9.5的django,这个命令很简明,可以适用其他通用库的安装)
安装MySQLdb
在官网下载msi安装包,直接安装下载即可*注意在安装中可能遇到找不到python27根目录的情况,这可能是因为你是64位的机器缺采用了32位的安装包,https://pypi.python.org/pypi/pip#downloads 这个网址中可以下载对应安装包
其他
在使用过程中可能遇到其他问题安装过程中出现错误,提示Pip 安装 出现UnicodeEncodeError: ‘ascii’ codec can’t encode characters
属于字符集问题,可以采用下面的方式解决1. 找到路径\Lib\site-packages
2. 路径下新建文件 sitecustomize.py ,文件内容为:
import sys
reload(sys)
sys.setdefaultencoding(‘utf-8’)
参见http://blog.csdn.net/a542551042/article/details/48676031
运行python manage.py runserver的时候提示.Django RuntimeError: maximum recursion depth exceeded
这个问题可能是因为python版本过来,库文件中存在bug未修复,可以尝试用下述方案解决To fix the problem replace this (about line 56 in python\Lib\fuctools.py):
convert = {
‘lt‘: [(‘gt‘, lambda self, other: other < self),
(‘le‘, lambda self, other: not other < self),
(‘ge‘, lambda self, other: not self < other)],
‘le‘: [(‘ge‘, lambda self, other: other <= self),
(‘lt‘, lambda self, other: not other <= self),
(‘gt‘, lambda self, other: not self <= other)],
‘gt‘: [(‘lt‘, lambda self, other: other > self),
(‘ge‘, lambda self, other: not other > self),
(‘le‘, lambda self, other: not self > other)],
‘ge‘: [(‘le‘, lambda self, other: other >= self),
(‘gt‘, lambda self, other: not other >= self),
(‘lt‘, lambda self, other: not self >= other)]
}
to that:
convert = {
‘lt‘: [(‘gt‘, lambda self, other: not (self < other or self == other)),
(‘le‘, lambda self, other: self < other or self == other),
(‘ge‘, lambda self, other: not self < other)],
‘le‘: [(‘ge‘, lambda self, other: not self <= other or self == other),
(‘lt‘, lambda self, other: self <= other and not self == other),
(‘gt‘, lambda self, other: not self <= other)],
‘gt‘: [(‘lt‘, lambda self, other: not (self > other or self == other)),
(‘ge‘, lambda self, other: self > other or self == other),
(‘le‘, lambda self, other: not self > other)],
‘ge‘: [(‘le‘, lambda self, other: (not self >= other) or self == other),
(‘gt‘, lambda self, other: self >= other and not self == other),
(‘lt‘, lambda self, other: not self >= other)]
}
参见http://stackoverflow.com/questions/16259729/django-python-manage-py-runserver-gives-runtimeerror-maximum-recursion-depth-e
在使用django时提示cannot import name patterns
这个错误是因为django版本与代码的版本不一致,可以通过确认支持该代码的django版本或者修改代码解决。参见http://stackoverflow.com/questions/22532743/cant-import-patterns-in-django
相关文章推荐
- windows2003+apache2.2+python2.7配置django mod_wsgi
- Django开发环境配置(Ubuntu16.0.4 + python 2.7 + Django 1.8.7 +Sublime2)
- window 环境下的python2.7环境配置和pip的环境配置
- window 下 python 2.7 安装 django 1.5
- Python2.7+Django1.8 [Windows7] 安装和配置
- Ubuntu14.04-Python2.7-Virtualenv-Django1.9-MySQL完整环境配置
- windows django 配置mysql (python2.7为例子)
- windows下安装django(python2.7)并配置mysql
- Django1.3.1 with python2.5 环境配置
- python下的web开发框架-Django,url配置
- Python+Django在windows下的开发环境配置
- Windows下Apache+mod_python+Django配置
- Linux 编译安装Nginx 配置 Python FastCGI Django (2) 安装python Django
- linux下 Apache mysql python mod_python Django 配置安装说明,绝对可以安装上的说明
- windows下配置python ,django,mysql,memcahe开发环境
- windowXP下解决python2.7+Django-1.3.1中:importError:no module named django.core
- python+apache+wsgi+django 按照手册配置还是报错原因
- eclipse+pydev+Django安装和配置Python开发环境(For Windows OS)
- Linux 编译安装Nginx 配置 Python FastCGI Django (3) 配置nginx和django
- Windows 7系统apache下配置python的django