linux安装python3环境并配置虚拟环境

1.安装必要库

yum -y install gcc
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 libffi-devel mysql-devel gcc gcc-devel python-devel

2.下载python源码:https://www.python.org/downloads/source/

# 下载源码
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
# 解压源码
tar -zxvf Python-3.8.2.tgz 
# 建立一个空文件夹,用于存放python3程序     
mkdir /usr/local/python3
# 执行配置文件,编译,编译安装
cd Python-3.8.2
./configure --prefix=/usr/local/python3
make && make install
# 建立软连接                     
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

3.测试python3和pip3

python3
pip3 --version

4.配置虚拟环境

# 安装virtualenv
pip3 install virtualenv -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com

# 安装virtualenvwrapper
pip3 install virtualenvwrapper -ihttps://pypi.douban.com/simple/ --trusted-host pypi.douban.com

# 配置环境变量vim /etc/bashrc,插入以下代码:
export WORKON_HOME=/data/virtualenv # 虚拟环境存放目录
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'#创建纯净环境,部分python3已放弃该参数
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 # python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/python3/bin/virtualenv
source /usr/local/python3/bin/virtualenvwrapper.sh

# 使环境变量立即生效
source /etc/bashrc

# 测试
workon
mkvirtualenv test
rmvirtualenv test

  

  

posted @ 2019-12-18 22:33  詹姆溪  阅读(1601)  评论(0编辑  收藏  举报