Linux系统下conda的安装与使用

1. 用wget命令下载

wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh

在这里插入图片描述

2 .安装命令

chmod 777 Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh

在这里插入图片描述
询问是否初始化Miniconda3时,选“no”
在这里插入图片描述

3 .验证conda是否安装成功

输入conda命令,如未成功输出,见下图
使用vim工具,编辑.bashrc文件,在最下行输入miniconda3的安装目录作为环境变量,与上面保存的安装目录相同

export  PATH="/root/miniconda3/bin:"$PATH

输入ESC、:、wq保存编辑
输入命令使.bashrc文件生效

source ~/.bashrc

输入conda命令,如正常返回,说明conda安装成功
在这里插入图片描述

4 .添加清华大学的镜像源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --set show_channel_urls yes 
conda config --get channels

在这里插入图片描述

5. 环境管理命令

可使用如下命令查看已有环境列表,*表示当前环境,base表示默认环境

conda env list

在这里插入图片描述
使用命令“conda create -n 环境名称 python=版本号”创建环境,这里创建了名称为3.7.1的python版本号为3.7.1的虚拟环境,稍微等待,过程中输入“y”。

 conda create -n test python=3.7.1

在这里插入图片描述查看环境列表,新环境已经创建好

conda env list

在这里插入图片描述
激活环境,默认处于base环境,进入其他环境需要使用source activate手动切换
在这里插入图片描述
若要退出当前环境,使用source deactivate,默认回到base 环境
在这里插入图片描述
这里提示命令“source deactivate”已经废弃了,使用“conda deactivate”

6 .进入环境安装依赖包

进入环境后,可使用如下命令安装依赖的包,使用的是已经配置好的清华的源,这里以“opencv-python”包为例,由于使用了清华大学的镜像源,下载速度很快。

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python

7.换回conda默认的源,访问起来可能有些慢,但总比无法访问好。

conda config --remove-key channels
发布了56 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_38627475/article/details/104503895