安装和使用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
相关推荐
坠金7 小时前
linux/centos迁移conda文件夹
linux·centos·conda
逍遥创江湖1 天前
包管理 pip ,conda;pycharm中使用conda 创建的虚拟环境
pycharm·conda·pip
淮北4942 天前
windows安装minicoda
windows·python·conda
Roc-xb3 天前
ModuleNotFoundError: No module named ‘conda_token‘
开发语言·python·conda
songyuc3 天前
【ChatGPT5】:“关于在当前 conda 环境里装 CUDA 12.8”
conda
woshihonghonga5 天前
停止Conda开机自动运行方法
linux·人工智能·conda
liliangcsdn5 天前
如何使用命令修改conda虚拟环境目录
conda
JANGHIGH6 天前
YOLO系列——Ubuntu20.04下通过conda虚拟环境安装Labelme
yolo·conda
Stestack7 天前
Linux - conda 环境安装教程
linux·conda
踏过山河,踏过海7 天前
【After Anaconda installation,conda can not run】
conda