阿里云CentOS 7.6 配置Python生产环境( python3.7.6 + Nginx + virtualenv)

发表时间:2020-03-13

第一步:安装Python3.7.6

1.安装 python3.7.6 源及依赖包

# yum install epel-release -y

# yum groupinstall "Development tools" -y

# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel zx-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel -y

2.编译安装 python3.7.6 以及 pip package manager

python3.7版本需要一个新的包libffi-devel

# wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz --no-check-certificate

# tar xf Python-3.7.6.tar.xz

# cd Python-3.7.6

# ./configure --prefix=/usr/local --with-ensurepip=install --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"

# yum install libffi-devel -y 

# make && make altinstall


第二步:安装Nginx

 1、安装nginx

yum install nginx

2、启动nginx

systemctl start nginx
systemctl enable nginx # 开机自启动

除了systemctl start nginx之外,常用的相关命令还有systemctl stop nginx、systemctl restart nginx、systemctl status nginx

3、测试nginx是否安装成功

浏览器输入ip地址或者域名(已经解析过的域名),如下图所示,则安装成功。

Snipaste_2020-03-12_09-41-20.png


第三步:配置虚拟环境virtualenv

1.安装 virtualenv

# pip3.7 install --upgrade pip


# pip3.7 install virtualenv

2.配置虚拟环境

# mkdir -p /usr/share/nginx/html/yuyin

# cd /usr/share/nginx/html/yuyin

# virtualenv -p /usr/local/bin/python3.7 .py3env

如图所示创建成功:

Snipaste_2020-03-12_09-49-57.png

3. 开启 virtualenv python3 环境

# source .py3env/bin/activate

使用语法:

开启: source 虚拟环境名称/bin/activate

退出:deactivate

注意:使用pip安装的内容都需要在虚拟环境下安装,否则将默认安装在Centos自带的Python2相关环境中

文章来源互联网,如有侵权,请联系管理员删除。邮箱:417803890@qq.com / QQ:417803890

微配音

Python Free

邮箱:417803890@qq.com
QQ:417803890

皖ICP备19001818号
© 2019 copyright www.pythonf.cn - All rights reserved

微信扫一扫关注公众号:

联系方式

Python Free