Rootop 服务器运维与web架构

centos7中利用conda实现多python版本

conda可以用来解决系统中多个python版本共存,也支持其他语言。
这里主要用来解决python3.8下写的脚本在centos7中运行。

conda安装需要 Anaconda 或 Miniconda,推荐安装Anaconda。区别去下面官方看。

下载地址:https://www.anaconda.com/distribution/#download-section
安装文档:https://conda.io/projects/conda/en/latest/user-guide/install/linux.html
Anaconda2 用于系统中python版本为2.x
Anaconda3 用于系统中python版本为3.x
我这里为centos7,下载Anaconda2版本的。

[root@localhost ~]# wget -c https://repo.anaconda.com/archive/Anaconda2-2019.10-Linux-x86_64.sh
[root@localhost ~]# bash Anaconda2-2019.10-Linux-x86_64.sh

最后他会提示是否init,输入yes初始化,重新ssh登录服务器。

(base) [root@localhost ~]# 

会看到前面有个 (base) ,这就是进去了conda环境中了。

# 创建一个python3.8的环境

(base) [root@localhost ~]# conda create --name py3 python=3.8

# 查看已有的环境

(base) [root@localhost ~]# conda info --envs
# conda environments:
#
base                  *  /root/anaconda2
py3                      /root/anaconda2/envs/py3

# 切换版本

(base) [root@localhost ~]# source activate py3
(py3) [root@localhost ~]# python -V
Python 3.8.2

# 退出conda环境

(base) [root@localhost ~]# source deactivate base
[root@localhost ~]# 

# 移除环境

[root@localhost ~]# conda remove -n py3 --all

这样就很方便把py3的脚本在centos中运行,而且不用更改系统python版本。

PS:清华镜像及加速配置:https://mirror.tuna.tsinghua.edu.cn/help/anaconda/

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4738.html

作者:Venus

服务器运维与性能优化

评论已关闭。