Ubuntu安装conda环境以及使用

一、下载conda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh 
# 或:
curl -O Miniconda3-latest-Linux-x86_64.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

# 赋予可执行权限
chmod +x Miniconda3-latest-Linux-x86_64.sh

# 执行脚本
./Miniconda3-latest-Linux-x86_64.sh
## 需要注意路径必须选择/usr/local/miniconda3,其他选yes
``

> 注意:如果没有wget和curl命令,需要使用apt来安装

### 二、配置环境变量
```bash
# 需要在家目录下的.bashrc追加以下内容
export CONDA_PATH="/usr/local/miniconda3"
export PATH="$PATH:$CONDA_PATH/bin"

三、conda命令使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 初始化环境
conda init bash

# 创建环境
conda create -n <名称> <软件名=版本号>

如:
conda create -n python3.10 python=3.10

# 查看虚拟环境
conda env list

# 进入虚拟环境
conda activate python3.10

# 退出虚拟环境
conda deactivate

# 删除虚拟环境
conda env remove -n python3.10

四、pip命令及配置

4.1 pip源配置:
官方源:

1
pip config set global.inedex-url https://pypi.org/simple/

第三方源:

1
2
3
4
5
6
7
8
# 清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# 阿里云源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

# 豆瓣源
pip config set global.index-url https://pypi.douban.com/simple/

企业吉利源(VDI研发内部):

1
pip config set global.index-url  https://pkg-rd.geely.com/artifactory/api/pypi/pypi-remote/simple

临时安装:

1
pip install <软件> -i <目标源>

五、pip升级

因为有些pip的依赖支持25版本需要做升级

1
2
3
# 进入虚拟环境
conda activate python3.10
pip install --upgrade -i https://pkg-rd.geely.com/artifactory/api/pypi/pypi-remote/simple

六、软件安装(示例)

1
2
3
4
5
6
7
8
## 安装torch模块
pip install torch torchaudio torchversion

## 查看已安装的模块
pip list

## 导出文件
pip freesz > requirements.txt

七、使用requirements.txt文件安装

1
pip install -r requirements.txt -i https://pkg-rd.geely.com/artifactory/api/pypi/pypi-remote/simple

Ubuntu安装conda环境以及使用
https://www.smallrains.com/posts/41143/
作者
小鱼不吃鱼.
发布于
2025年6月1日
许可协议