简单介绍在Ubuntu上安装Python的virtualenv

前提:本机安装了Linux系统 (这里推荐用Ubuntu安装,或是CentOS)

(Ubuntu的安装比较简单,推荐用VirtualBox,可以去Oracle官网下载VirtualBox(https://www.virtualbox.org/) ,然后去Ubuntu官网(https://www.ubuntu.com/download) 下载Ubuntu,可以下载桌面版或是服务器版,安装好VirtualBox后,启动VirtualBox,然后选择添加操作系统(可以搜索一下Ubuntu的安装),操作完成后,启动Ubuntu

假设Ubuntu已经安装好了
Ubuntu带有Python 2.7和Python3.x,这里我们选择用Python3
为了快速地下载软件包,可以事先更改一下Ubuntu系统的更新源,默认是US的,我们可以更改为阿里云**

更改Ubuntu更新源:
(Ubuntu的更新源在 /etc/apt/sources.list)
备份一下这个文件 sudo cp /etc/apt/source.list /etc/apt/source.list.bak
用vi或vim打开这个文件 sudo vim /etc/apt/sources.list
*替换文件里的更新地址,可以注释所有地址先 (这里我们用阿里云的更新源,基于Ubuntu17.10,可以查看一下Ubuntu系统的代号 lsb_release -a,这里是artful)
粘贴下面的地址到source.list文件,然后保存退出

deb http://mirrors.aliyun.com/ubuntu/ artful main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ artful-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ artful-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ artful-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ artful-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful-updates main multiverse restricted universe

然后更新 sudo apt-get update,是刚才的改动生效
上面这个设置改动就可以使用国内的更新源了,如果你是用的Ubuntu桌面,则可以直接在系统设置里更改)

##接下来安装virtualenv

Step 1: login Ubuntu
Step 2: Open terminatewith (Ctrl+Alt+T) (if installed Ubuntu Desktop)
Step 3: Check Python version with command: python3 -V (Python2.7 and Python 3.x have been installed in Ubuntu)
Step 4: Install pip sudo apt-get install python3-pip
Step 5: Check pip version pip3 -V (assumed that pip install successful)
Step 6: Install virtualenv pip3 install virtualenv (check virtualenv version virtualenv --version if install successful)
Step 7: Create a virutal env with command virtualenv venv
Step 8: Activate virtual env with source ./bin/activate (if venv install successful, then created a venv directory, ./bin/activate is based on current directory)

pipenv 可以看官方的文档: https://pypi.python.org/pypi/pipenv
这里很详细的介绍了pipenv的应用,这也是official recommend