conda安装及配置

Maple

What is conda

Anaconda开发的Conda是一个优秀的python包管理器,可以快速解决包的版本依赖问题。同时,利用anaconda安装的python,预置了一系列对科研有用的python包如NumPy、SciPy等。

Install

Anaconda can be Free Downloaded. When Install, it is ok to take all setting in default.

Configuration

由于一些众所周知的原因,使用conda进行包下载时速度极慢。可以通过替换镜像源来改善速度,网上相关教程非常丰富,笔者位于深圳,使用南科大镜像站速度极快,所以这里以南科大镜像站举例。通常而言,conda会将channels存储在用户目录的.condarc文件中。可以通过命令添加频道:

1
conda config --add channels https://mirrors.sustech.edu.cn/anaconda/pkgs/main

如果需要换回conda的默认源,直接删除channels即可,命令如下:

1
conda config --remove-key channels

或直接修改.condarc文件内容更加。

Windows

Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。

Linux and MacOS

直接在用户目录创建文件.condarc添加文本即可。

按照如下内容写入,可覆盖绝大多数应用场景。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
channels:
- defaults
show_channel_urls: true
default_channels:
- http://mirrors.sustech.edu.cn/anaconda/pkgs/main
- http://mirrors.sustech.edu.cn/anaconda/pkgs/r
- http://mirrors.sustech.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: http://mirrors.sustech.edu.cn/anaconda/cloud
msys2: http://mirrors.sustech.edu.cn/anaconda/cloud
bioconda: http://mirrors.sustech.edu.cn/anaconda/cloud
menpo: http://mirrors.sustech.edu.cn/anaconda/cloud
pytorch: http://mirrors.sustech.edu.cn/anaconda/cloud
pytorch-lts: http://mirrors.sustech.edu.cn/anaconda/cloud
simpleitk: http://mirrors.sustech.edu.cn/anaconda/cloud

Config pip

May be you also want to change default source of pip.

1
2
pip install --upgrade pip --index-url https://mirrors.sustech.edu.cn/pypi/web/simple
pip config set global.index-url https://mirrors.sustech.edu.cn/pypi/web/simple

How to use

Usually, you need to run conda init first to let conda auto activate in you shell. You can also run {PathWhereYouInstallConda}/bin/conda activate {YourEnv} every time.

Create new environment

conda create -n {YouEnvName} (python=3.11)
e.g.

1
conda create -n gdstk

e.g. From env.yml

1
conda env create -f env.yml

Activate your env

conda activate {YourEnv}
e.g.

1
conda activate gdstk

Install package

conda install (-c {SpecifiedChannel}) {Package}
e.g.

1
conda install -c conda-forge gdstk

Update package

conda update {Package}

Remove package

conda remove {Package}

Check package

conda list

Export your env

conda env export -n {ENVIRONMENT} -f {FILE}

  • Title: conda安装及配置
  • Author: Maple
  • Created at : 2023-11-08 13:25:42
  • Updated at : 2025-03-04 15:43:38
  • Link: https://www.maple367.eu.org/Code/Python/conda安装及配置/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments