linux 环境下配置python虚拟环境

  系统Ubuntu 16.0.4, 环境自带python2.7和python3.5,现在我想创建 python3.5的虚拟环境,下面介绍最好的方法。

 1、使用update-alternatives命令切换python版本

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

 返回 python2 sudo update-alternatives --config python

 2、安装创建虚拟环境的 virtualenvwrapper包

pip install virtualenvwrapper

 3、配置环境

  首先找到配置virtualenvwrapper的配置文件

find / -name virtualenvwrapper.sh

  找到路径之后在/etc/profile中进行配置:

export WORKON_HOME=/root/envs_workspace  // 默认虚拟环境目录
source /usr/local/bin/virtualenvwrapper.sh

  使用 virtualenvwrapper

source /etc/profile
mkvirtualenv test  //创建虚拟环境test

 当然, virtualenvwrapper 还有很丰富的操作,让你能轻松创建管理虚拟环境,其他常用命令请参考我之前写的的博客windows环境下python 虚拟环境的创建和使用(virtualenvwrapper)

猜你喜欢

转载自blog.csdn.net/jeffery0207/article/details/80101935