DJango - 部署指南
说明
本文描述 Centos 7 + DJango 1.8 安装方法
不建议使用 centos 7 自带的 DJango rpm 进行安装
rpm 安装的 DJango 无法使用本文中的启动脚本
需求
epel-release-7 RPM
当前使用 rhel7 默认 python 2.7 版本
安装方法
rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
更新软件源方法
yum makecache
DJango 软件安装
1 安装 python-pip
yum install -y python-pip
2 可以选择更新一下pip
pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 330kB/s
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-18.1
3 利用 python-pip 安装 DJango 软件
python -m pip install "django<2"
Downloading https://files.pythonhosted.org/packages/44/e7/872bbf76aa16b7a061698d75325dac023285db33db4bda8ba8fe5d3bb356/Django-1.11.16-py2.py3-none-any.whl (7.0MB)
100% |████████████████████████████████| 7.0MB 563kB/s
Collecting pytz (from django<2)
Downloading https://files.pythonhosted.org/packages/30/4e/27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-py2.py3-none-any.whl (510kB)
100% |████████████████████████████████| 512kB 680kB/s
Installing collected packages: pytz, django
Successfully installed django-1.11.16 pytz-2018.5
4 利用 pip 安装一些常用的 python 库文件方法
pip install --upgrade setuptools
pip install six --upgrade --ignore-installed six
pip install djangorestframework <- rest_framework 框架
pip install django-filter
pip install mysql-connector-python <- 数据库连接库
pip install PyMySQL <- 数据库连接库
pip install simplejson
pip install uwsgi <- uwsgi 服务,用于支持 DJango 框架
pip install enum34
温馨提示:
在安装 uwsgi 时, 假如如果了下面的错误
InsecurePlatformWarning
Using cached https://files.pythonhosted.org/packages/a2/c9/a2d5737f63cd9df4317a4acc15d1ddf4952e28398601d8d7d706c16381e0/uwsgi-2.0.17.1.tar.gz
Installing collected packages: uwsgi
Running setup.py install for uwsgi ... error
Complete output from command /usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-3ZUXQt/uwsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-sFae9c/install-record.txt --single-version-externally-managed --compile:
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'descriptions'
warnings.warn(msg)
running install
using profile: buildconf/default.ini
detected include path: ['/usr/include', '/usr/local/include']
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-3ZUXQt/uwsgi/setup.py", line 138, in <module>
'Programming Language :: Python :: 3.6',
File "/usr/lib/python2.7/site-packages/setuptools/__init__.py", line 140, in setup
return distutils.core.setup(**attrs)
File "/usr/lib64/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/tmp/pip-install-3ZUXQt/uwsgi/setup.py", line 77, in run
conf = uc.uConf(get_profile())
File "uwsgiconfig.py", line 750, in __init__
raise Exception("you need a C compiler to build uWSGI")
Exception: you need a C compiler to build uWSGI
需要安装 C rpm 包解决
yum install -y gcc
假如遇到下面错误
compilation terminated.
In file included from plugins/python/web3_subhandler.c:1:0:
plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
----------------------------------------
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-uUo3ih/uwsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-dyNXGe/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-uUo3ih/uwsgi/
需要安装 python-devel rpm 包解决
yum install -y python-devel
验证
利用命令行输入命令看见返回即可
django-admin --help
Type 'django-admin help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
....
还没有评论,来说两句吧...