Environment: centos7 + python3.6
Preparatory work, build the project requirements.txt files, used to store third-party libraries and version information: pip freeze> requirements.txt, and uploaded to the server
A: Prepare python virtual environment
the install the virtualenv PIP
PIP virtualenvwrapper the install
installation virtualenvwrapper automatically installs virtualenv, it is mounted directly virtualenvwrapper
specified here faster installation speed of some watercress source: pip install -i https://pypi.douban.com/simple virtualenvwrapper
The installation is complete there will be a virtualenvwrapper.sh file, find the file location: whereis virtualenvwrapper.sh
Set the environment variables: vim ~ / .bashrc
At the end of file add
Export WORKON_HOME the HOME = $ / .virtualenvs
VIRTUALENVWRAPPER_PYTHON = / usr / local / Python / bin / python3 prevent find python2, here designated python3
Source /usr/local/python/bin/virtualenvwrapper.sh
source and let the variables to take effect: source ~ / .bashrc
Create a virtual environment: mkvirtualenv environment name, the installation is complete will automatically enter the virtual environment
virtualenvwrapper常用命令列表
workon:列出虚拟环境列表
lsvirtualenv:同上
mkvirtualenv :新建虚拟环境
workon [虚拟环境名称]:切换虚拟环境
rmvirtualenv :删除虚拟环境
deactivate: 离开虚拟环境
进入虚拟环境,进项目requirements.txt所在目录,安装第三方库,同样,这里为了速度快些,使用豆瓣的源:
pip install -i https://pypi.douban.com/simple -r requirements.txt
二:安装mysql数据库见:https://www.cnblogs.com/zhongyehai/p/10475646.html
这里设置用户:root,密码:Admin123@qwe
创建数据库,数据库名与项目里面的数据库名一致,编码为utf8:create database test charset utf8;
由于数据库密码不一致,这里修改连接的信息,再执行数据库迁移
python manager.py db init
python manager.py db migrate
python manager.py db upgrade
把项目要用的端口开放
firewall-cmd --permanent --zone=public --add-port=8000/tcp
firewall-cmd --reload
普通运行模式运行看一下能不能访问
查询字符串的形式访问的接口,没有报错,说明数据库链接成功,没有查到数据是因为本身就没有数据