03月25, 2020

CentOS7安装Python3.7

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. 下载并解压安装包

> cd /srv/src
> wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tgz
> #tar -xvJf  Python-3.7.0.tar.xz
> tar -zxvf Python-3.7.0.tgz

3. 编译及安装

> cd Python-3.7.7
> ./configure
> ./configure --enable-optimizations
> make && make install

4. 验证

python3 -V
pip3 -V

5. 升级pip

> pip3 install --upgrade pip

6. 安装virtualenv

> pip3 install virtualenv
> pip3 install virtualenvwrapper

7. 配置virtualenv

PL_HOME="/srv/PL"
## Python
export VIRTUALENVWRAPPER_PYTHON="/usr/local/bin/python3"
export WORKON_HOME="$PL_HOME/Python/virtualenvs"
source /usr/local/bin/virtualenvwrapper.sh

8. virtualenv常用命令

# 创建python虚拟环境
> mkvirtualenv -p /usr/local/bin/python3.7 py3.7

# 查看已经创建的python虚拟环境
> lsvirtualenv

# 使用python虚拟环境
> workon py3.7

# 停止使用python虚拟环境
> deactivate

删除python虚拟环境
> rmvirtualenv py3.7

本文链接:http://www.reesun.xyz/post/CentOS7-an-zhuang-Python3.7.html

-- EOF --