centos系统python3.7安装及虚拟环境部署

1、配置yum国内镜像

1)备份源:

#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2)下载源:

#wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

#mv CentOS6-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo

3)生成缓存使配置生效

#yum clean all

#yum makecache

2、Python3.7.3安装

1)安装编译相关工具

#yum -y groupinstall "Development tools"

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

#yum install libffi-devel –y

2)下载安装包解压

#wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz

#tar -xvJf Python-3.7.3.tar.xz

3)预编译安装

#mkdir /usr/local/python3

4)创建编译安装目录

#cd Python-3.7.3

#./configure --prefix=/usr/local/python3

#make && make install

5)创建软连接

#ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3

#ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

3、安装Python虚拟环境

1)更新pip3

# pip3 install --upgrade pip

2)安装virtualenv

#pip3 install virtualenv

#pip3 install virtualenvwrapper

3)配置环境变量

#mkdir /root/.virtualenvs

#vi ~/.bashrc 

#VIRTUALENVWRAPPER_PYTHON=/usr/local/python3/bin/python3 # 指定virtualenvwrapper执行的python版本
#export WORKON_HOME=/root/.virtualenvs  #虚拟环境存放目录
#source /usr/local/python3/bin/virtualenvwrapper.sh

#source  ~/.bashrc

4)创建虚拟环境

#mkvirtualenv metesys-env

这里出现错误:virtualenvwrapper could not find virtualenv in your path

查找virtualenv:find / -name virtualenv,输出:/usr/local/python3/bin/virtualenv

创建软连接

# ln -s /usr/local/python3/bin/virtualenv /usr/local/bin/virtualenv

再次执行创建命令

centos系统python3.7安装及虚拟环境部署_第1张图片

5)使用虚拟环境

选择虚拟环境:#workon 两次tab键

退出虚拟环境:# deactivate

删除虚拟环境:#rmvirtualenv name

你可能感兴趣的:(python)