上篇文章配置了虛機基礎(chǔ)環(huán)境,本篇文章介紹配置python開發(fā)環(huán)境
配置YUM源
使用國內(nèi)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
安裝相關(guān)依賴
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并初始化環(huán)境
初始化環(huán)境,推薦使用普通用戶
/usr/local/python36/bin/pip3 install virtualenv
/usr/local/python36/bin/virtualenv ./python36env
安裝django
source /data/python36env/bin/activate
pip install django
安裝數(shù)據(jù)庫
安裝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
初始化數(shù)據(jù)庫
mysql_secure_installation
安裝mysqlclient
source /data/python36env/bin/activate
pip install mysqlclient
創(chuàng)建數(shù)據(jù)庫
mysql -uroot -p123456 -e "create database django CHARACTER SET utf8;"
開發(fā)工具配置
安裝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 數(shù)據(jù)庫配置
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;',
},
}
}