centos 6 搭建django环境

1、获取django安装包

wget https://www.djangoproject.com/m/releases/1.9/Django-1.9.1.tar.gz

2、解压缩并更名为django

tar -zxvf Django-1.9.1.tar.gz
mv Django-1.9.1 django 

3、执行安装

cd django 
python setup.py install

遇到报错

Traceback (most recent call last):
  File "setup.py", line 32, in <module>
    version = __import__('django').get_version()
  File "/root/yupen1/django/django/__init__.py", line 1, in <module>
    from django.utils.version import get_version
  File "/root/yupen1/django/django/utils/version.py", line 7, in <module>
    from django.utils.lru_cache import lru_cache
  File "/root/yupen1/django/django/utils/lru_cache.py", line 28
    fasttypes = {int, str, frozenset, type(None)},
                    ^
SyntaxError: invalid syntax

检查一下,发现CentOS6.5 的 python版本太老,的 Python是2.6.6,而最新的django 1.9 要求的 Python 版本是2.7.x

接下来把python 升级到2.7
3.1、下载python2.7

wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
tar -zxvf  Python-2.7.11.tgz 
mv Python-2.7.11 python

3.2、 编译安装

yum install gcc     #如果安装了gcc请忽视
./configure --prefix=/usr/local/python2.7
make && make install 

3.3、此时没有覆盖原来的版本,再将原来/usr/bin/python链接改为别的名字并重新建立软链接

mv /usr/bin/python /usr/bin/python_bak
ln -s  /usr/local/python2.7/bin/python2.7  /usr/bin/python

3.4、 再次运行 python setup.py install 提示 ImportError: No module named setuptools
安装setuptools就行了

tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install

4、再次运行

 python setup.py install

django 1.9就安装完成了。

centos安装django 1.9

未经允许不得转载:晨飞小窝 » centos 6 搭建django环境

赞 (0)

评论 0