由于项目使用Django1.7.1,It works with Python 2.7,3.2, 3.3, or 3.4,而我的CentOS x86 64bit系统自带的Python版本是2.6.6,故需要升级为Python2.7版本。
升级工作是参照网上的3篇文章完成,只是需要注意3点:
(1)因为系统现有的某些软件是依赖python2.6.6的,所以不能卸载现有版本之后重新安装python2.7,否则直接升级到python2.7之后可能会导致yum等不能使用。
参见文章:,完成python2.6.6升级为Python2.7.3。
(2)为了避免进入python解释器环境时方向键乱码的问题,最好在升级之前确认是否安装了readline-devel模块。
(3)完成升级之后,进入python解释器中执行import django时,会报错:ImportError: No module named django。
参见文章:,设置环境变量:PYTHONPATH即可解决。
附:如果使用pip安装的Django,可以执行如下命令查看当前Django的安装目录:
pip show Django
(4)另外,在升级完成之后又遇到的了新的问题。执行:”django-admin.py startproject ttt“时报错:
Traceback (most recent call last):
File "/usr/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 385, in
execute_from_command_line
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 354, in
execute
django.setup()
File "/usr/lib/python2.6/site-packages/django/__init__.py", line 18, in setup
from django.utils.log import configure_logging
File "/usr/lib/python2.6/site-packages/django/utils/log.py", line 13, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/usr/lib/python2.6/site-packages/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/usr/lib/python2.6/site-packages/django/http/__init__.py", line 2, in <module>
from django.http.request import (HttpRequest, QueryDict,
File "/usr/lib/python2.6/site-packages/django/http/request.py", line 12, in <module>
from django.core import signing
File "/usr/lib/python2.6/site-packages/django/core/signing.py", line 41, in <module>
import zlib
ImportError: No module named zlib
是因为缺少zlib-devel包,解决方法如下:
安装zlib-devel包
shell>sudo yum install zlib-devel
重新编译安装Python
shell>./configure --with-zlib
shell>make
shell>sudo make install
在安装MySQLdb模块时,总是报错,后来在文件setup.cfg中看到一句话:
build-requires = python-devel mysql-devel zlib-devel openssl-devel
果断先安装需要依赖的软件包:
yum install python-devel mysql-devel zlib-devel openssl-devel
OK! 问题解决。
--------------------------------------分割线 --------------------------------------
《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版]
《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码]
在Ubuntu下用Python搭建桌面算法交易研究环境