python 开发环境配置

上篇文章配置了虚机基础环境,本篇文章介绍配置python开发环境

配置YUM源

使用国内yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-
Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-7.repo

安装python

安装相关依赖
sudo yum -y install openssl-devel readline-devel unzip
编译安装python
下载python源码包
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
安装
tar -xzf Python-3.6.2.tgz
./configure --prefix=/usr/local/python36
make && make install
修改pip配置
sudo tee /etc/pip.conf <<EOF
[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
[list]
format=columns
EOF
安装vartualenv并初始化环境
初始化环境,推荐使用普通用户
/usr/local/python36/bin/pip3 install virtualenv

/usr/local/python36/bin/virtualenv ./python36env
安装django
source /data/python36env/bin/activate
pip install django

安装数据库

安装mariadb
yum -y install mariadb mariadb-server mariadb-devel
修改/etc/my.cnf配置
[mysqld]
default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8
启动服务
systemctl start mariadb
systemctl enable mariadb
初始化数据库
mysql_secure_installation
安装mysqlclient
source /data/python36env/bin/activate
pip install mysqlclient
创建数据库
mysql -uroot -p123456 -e "create database django CHARACTER SET utf8;"

开发工具配置

安装vim
yum -y install vim
配置vim
tee ~/.vimrc <<EOF
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set fileformat=unix
set nobomb
set ff=unix
set ambiwidth=double
set fileencodings=utf-8,ucs-bom,cp936
syntax on
filetype plugin on
set nocompatible
set completeopt=preview
set ai
set hls
set nu
EOF

django 数据库配置

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '127.0.0.1',
'PORT': 3306,
'OPTIONS':{
'init_command': 'SET default_storage_engine=INNODB;',
},
}
}

推荐阅读更多精彩内容