conda 管理多版本python

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wild46cat/article/details/81638858

如题,在平时的开发中经常会有使用多个python版本的时候。conda能够进行python的版本管理。这里介绍一下如何安装和使用conda。

好,下面上货。

来自百度的一个介绍:

Conda 是一个开源的软件包管理系统和环境管理系统,用于安装多个版本的软件包及其依赖关系,并在它们之间轻松切换。

简单的说就是可以使用conda对虚拟出多个python环境。然后可以每次选择一个python进行你的开发,然后在切换回去。比如默认的base版本是3的,我们现在想要安装一个python2.7的版本,可以在conda中虚拟出这样的版本,同时,也能够虚拟出python2.7以来的软件包。当我们使用完python2.7后,可以保留这个环境,或者选择删除掉。

1、安装conda。

参考这里:https://askubuntu.com/questions/505919/how-to-install-anaconda-on-ubuntu

进入网站下载conda

https://www.anaconda.com/download/#linux

查看conda版本

conda --version

查看当前环境

conda info -e

2、如果上面的命令已经ok,那么可以替换成国内的源

conda使用国内源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

conda config --set show_channel_urls yes

3、使用conda进行版本管理

参考文章:

https://jingyan.baidu.com/album/22a299b5e6e4909e18376a4b.html?picindex=6

4、尝试使用conda

4.1创建一个新的环境python27

conda create --name xypy27 python=2.7

wildcat@:~$ conda info -e

# conda environments:

#

base * /home/wildcat/anaconda3

xypy27 /home/wildcat/anaconda3/envs/xypy27

4.2 conda能够构建出当前系统的python使用的版本,如果需要安装其他的包,比如qiniu等,可以在不同的环境中使用pip。

conda能够安装到当前的环境中。换句话说就是,conda已经把每一个环境进行了区分。

(xypy27) wildcat@:~$ conda list

# packages in environment at /home/wildcat/anaconda3/envs/xypy27:

#

# Name Version Build Channel

certifi 2016.2.28 py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

certifi 2018.4.16 <pip>

chardet 3.0.4 <pip>

idna 2.7 <pip>

openssl 1.0.2l 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

pip 9.0.1 py27_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

pip 18.0 <pip>

python 2.7.13 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

qiniu 7.2.2 <pip>

readline 6.2 2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

requests 2.19.1 <pip>

setuptools 36.4.0 py27_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

sqlite 3.13.0 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

tk 8.5.18 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

urllib3 1.23 <pip>

wheel 0.29.0 py27_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

zlib 1.2.11 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free

删除不需要的安装包可以直接使用pip uninstall qiniu

4.3删除不需要的环境版本

conda remove --name python27 --all

5、需要强调一下需要使用到的常用的命令:

进入到指定的环境中

source activate xypy27

离开当前环境回到base环境

source deactivate xypy27

猜你喜欢

转载自blog.csdn.net/wild46cat/article/details/81638858
今日推荐