centos 安装python3虚拟环境

安装环境

系统版本:CentOS 7.4(自带Python2.7)
安装版本:Python3.6
安装插件:virtualenv、virtualenvwrapper

which python

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

下载Python3安装包

wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
mkdir /usr/local/python3 
tar -xvJf  Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install

安装Python3时,会自动安装pip。假如没有,需要自己手动安装。这里我的有了

yum -y install python-pip

创建软链接

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

安装完输入python3 试试。

创建虚拟环境

pip3 install --upgrade pip
pip3 install virtualenv
pip3 install virtualenvwrapper

vi ~/.bashrc

在文末填入以下代码并保存

VIRTUALENVWRAPPER_PYTHON=/usr/local/python3/bin/python3    # 指定virtualenvwrapper执行的python版本
export WORKON_HOME=$HOME/.virtualenvs    # 指定虚拟环境存放目录,.virtualenvs目录名可自拟
source /usr/local/bin/virtualenvwrapper.sh    # virtualenvwrapper.sh所在目录
source ~/.bashrc
mkvirtualenv -p python3 py3_flask
workon py3_flask

中间有错的
-bash: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
查找virtualenvwrapper.sh所在目录

find / -name "virtualenvwrapper.sh"

添加正确这个

你可能感兴趣的:(centos 安装python3虚拟环境)