安装和使用conda

Conda 是一个开源的软件包管理系统和环境管理系统,用于安装多个版本的软件包及其依赖关系,并在它们之间轻松切换。可以创建多个环境,并在环境中使用不同的python版本,并安装环境专属的python依赖包,可以用来避免python项目依赖冲突的问题。

conda用户引导

https://conda.io/projects/conda/en/latest/user-guide/getting-started.html

安装

Anaconda-Navigator 下载地址

根据个人的操作系统环境下载对应的版本,然后本地安装即可。

安装完成后会出现Anaconda-Navigator这个应用,并且在终端中就可以使用conda命令了

配置conda镜像源

由于使用conda安装第三方包的时候,默认是国外的镜像很容易出现安装失败,所以需要添加国内的镜像源,这里推荐配置清华的镜像源。

使用终端输入以下命令

bash 复制代码
echo "channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud" > ~/.condarc

清除索引缓存,保证用的是镜像站提供的索引

bash 复制代码
conda clean -i

查看配置,输入下面的命令,出现了https://mirrors.tuna.tsinghua.edu.cn的关键字,就说明配置成功了

bash 复制代码
conda config --show

配置pip的安装源

很多项目一般使用pip去依赖的,不切换镜像源同样会有安装依赖慢的问题,这里设置一下pip的安装源

bash 复制代码
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/

查看配置的安装源 pip config get global.index-url

bash 复制代码
pip config get global.index-url

输出https://pypi.tuna.tsinghua.edu.cn/simple/就表示配置成功了

Anaconda-Navigator使用

创建环境

输入环境名称,最好是英文,然后选择需要的python版本,点击创建即可

打开终端并进入某个环境

包搜索

https://anaconda.org/

命令行操作

大部分功能直接使用Anaconda-Navigator也可以

创建环境
bash 复制代码
conda create -n <env-name>
# 创建并安装依赖
conda create -n <env-name> python numpy pandas
指定环境中的python版本
bash 复制代码
# 在创建环境时安装指定的python版本
conda create -n <env-name> python=3.11
# 切换到某个环境里然后更新python
conda install python=3.12
查看环境
bash 复制代码
conda info --envs
删除环境
bash 复制代码
conda env remove -n env_name
激活环境
bash 复制代码
conda activate 环境名称
安装依赖

建议进入某个环境后安装

bash 复制代码
conda install 包名
# 或者
pip install 包名
卸载第三方包
bash 复制代码
conda remove numpy
# 或者
pip uninstall numpy
# 删除所有
conda remove --all
查看安装的依赖
bash 复制代码
conda list
导入导出环境

导出当前环境的包信息可以用

bash 复制代码
conda env export > 具体路径
# eg:conda env export > C:\Users\pc\Desktop\environment.yaml

用配置文件(yaml)创建新的虚拟环境

bash 复制代码
conda env create -n 环境名 -f C:\Users\pc\Desktop\environment.yaml
更新conda
bash 复制代码
conda update conda
相关推荐
code_talking17 小时前
Python学习第十七天之PyTorch保姆级安装
人工智能·pytorch·python·conda
马圈圈马18 小时前
服务器间迁移conda环境
运维·服务器·pytorch·深度学习·conda
drebander2 天前
使用 Conda 管理 R 语言
开发语言·r语言·conda
soumns丶涛3 天前
“conda”不是内部或外部命令,也不是可运行的程序或批处理文件
windows·python·jupyter·conda
HHUCESTA3 天前
2025年信息科学与工程学院科协机器学习介绍——conda环境配置
人工智能·机器学习·conda
一穷二白到年薪百万3 天前
【R安装包报错】在conda环境下用R语言命令安装R包报错
conda·生物信息
哎呀——哪是啥4 天前
更改conda 环境默认安装位置
conda
竹泉听风6 天前
ADCP处理软件CODAS安装 (conda方法安装)
conda
_Johnny_6 天前
conda 配置源
conda
sun lover7 天前
conda简单命令
python·conda