首頁 > 軟體

Django環境安裝部署

2020-06-16 17:21:51

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還是報錯:

[root@a.adddisk.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

Ubuntu 14.04下Django+MySQL安裝部署全過程 http://www.linuxidc.com/Linux/2016-02/128714.htm

Ubuntu 16.04下安裝部署 Nginx+uWSGI+Django1.9.7  http://www.linuxidc.com/Linux/2016-07/133484.htm

Ubuntu 16.04下設定Django專案 http://www.linuxidc.com/Linux/2017-01/139417.htm


IT145.com E-mail:sddin#qq.com