django环境部署

django版本1.7以后不支持python2.6,因此需要给python升级

安装Python-2.7.11
安装各种依赖包

yum -y install zlib zlib-devel gcc  openssl openssl-devel sqlite sqlite-devel mysql-devel python-devel mysql-python
#python 交互模式上下左右键乱码乱码,需安装readline-devel 
yum -y install readline-devel 
mkdir /usr/local/python27
tar zxf Python-2.7.11.tgz;cd Python-2.7.11;
./configure -prefix=/usr/local/python27 

取消注释Modules/Setup中的467行:

zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib –lz
make && make install

安装好后更改环境变量

mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/python27/bin/python /usr/bin/python
#不能省,安装的pip位于该/usr/local/python27/bin
echo export PATH=$PATH:/usr/local/python27/bin >> /etc/profile
source /etc/profile

python -V,查看版本号
此时得更改yum命令,vim /usr/bin/yum 第一行为#!/bin/python2.6.6,否则无法使用
安装pip
1. 安装zlib,zlib-devel,gcc,安装pip时需要,否则报zipimport.ZipImportError: can’t decompress data; zlib not available,编译python后可能需要注释Modules/Setup中的467行:

zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib –lz

安装openssl和openssl-devel,安装pip时需要,否则报ImportError: cannot import name HTTPSHandler

yum -y install openssl openssl-devel
  1. 安装setuptools
    wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg –no-check-certificate
    chmod +x setuptools-0.6c11-py2.7.egg
    bash setuptools-0.6c11-py2.7.egg
  2. 下载get-pip.py
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
python get-pip.py

升级python后的问题
①yum不能用,报错:no model named yum
更改/usr/bin/yum第一行为: #!/usr/bin/python2.6

②easy_install 不能用,报错:
pkg_resources.DistributionNotFound: distribute==0.6.10
原因是:这是python2.6版的,升级了python后,新的easy_install,位于/usr/local/python27/bin/easy_install-2.7,删除/usr/bin/easy_install*,或用命令的全路径执行:

/usr/local/python27/bin/easy_install --upgrade pip

又是报错:
Couldn’t find a setup script in /usr/local/python27/lib/python2.7/site-packages/pip
这是由于不能在python2.7/site-packages/目录下执行easy_install,换个目录, cd .. ;然后再执行试试,参考如下方法解决的,我也是醉了
http://stackoverflow.com/questions/6178664/easy-install-fails-on-error-couldnt-find-setup-script-after-binary-upload

③升级pip后,pip install django还是报错:

[[email protected].001 apps]# pip2.7 install django
Collecting django
  Could not find a version that satisfies the requirement django (from versions: 1.7plus-email503-0.1)
No matching distribution found for django

安装django
④用easy_install 安装django,居然ok了。pip安装为什么失败没搞明白。

/usr/local/python27/bin/easy_install  django

Django安装完成,新建项目测试
安装mysql-python时,python setup.py install报错
command ‘gcc’ failed with exit status 1
可是已经装了gcc了。
是由于没有装mysql-devel,python-devel,mysql-python

yum -y install mysql-devel python-devel mysql-python

你可能感兴趣的:(django,python)