Ubuntu 安装virtualenv

[TOC]

Ubuntu 安装virtualenv

一、安装pip

1、安装pip

sudo apt-get install python3-pip -y
# sudo apt-get install python2-pip -y

2、配置pip源

sudo mkdir ~/.pip
sudo cat << EOF > ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
EOF

二、安装virtualenv

1、安装virtualenv

sudo pip3 install virtualenv

2、配置virtualenv环境

find ~/ -name virtualenv
/home/hxy/.local/bin/virtualenv

cat << EOF > ~/a
export PATH=$PATH:/home/hxy/.local/bin
EOF

三、配置virtualenv环境

1、创建虚拟环境

virtualenv --python=/usr/bin/python3 py3
$ ls
bin  include  lib

2、激活使用环境

cd py3
$ ls
bin  include  lib
$ cd bin/
$ ls
activate       activate.ps1      easy_install      pip3    python3        wheel
activate.csh   activate_this.py  easy_install-3.6  pip3.6  python3.6
activate.fish  activate.xsh      pip               python  python-config
# 激活
$ source activate
(py3) [18:17:43]:~/py3/bin
# 关闭

3、相关命令

# 创建python系统默认的虚拟环境
virtualenv pyenv

# 创建python3虚拟环境
virtualenv --python=/usr/bin/python3 py3env

相关推荐