conda安装与使用

本地部署阿里的 SenseVoice 时发现,依赖于 ffmpeg 这种非 python 包,pip 没办法直接管理,但我又不想系统层面全局装,这时候发现 conda 可以实现代码项目层级的依赖包隔离。

1 安装

1.1 Mac 上安装

# 用homebrew安装
brew install miniconda
# 检查是否安装成功
conda --version

Windows 上安装

# 1 用winget安装
winget install miniconda3
# 2 添加到环境变量,使得windows终端可识别conda命令
# 3 检查是否安装成功
conda --version

2 使用

2.1 创建 conda 环境

# 用配置文件创建conda环境
conda env create -f environment.yml
# 激活conda环境
conda activate ai-env

阿里 SenseVoice 和 CosyVoice 的依赖环境配置如下

name: ai-env
channels:
- conda-forge
- defaults
dependencies:
- python=3.12
- ffmpeg # 音频转码
- pip
- pip:
- flask
- gunicorn # web容器
- python-magic # 多媒体格式
- pydub # 音频处理
- modelscope # 魔搭社区-阿里
- funasr # 语音识别-阿里
- torch # Pytorch深度学习核心库
- torchaudio # Pytorch框架音频处理

其中的channels可以换成国内的 conda 镜像源:中科大、清华、阿里云

channels:
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
channels:
- https://mirrors.aliyun.com/anaconda/pkgs/main/
- https://mirrors.aliyun.com/anaconda/pkgs/free/
- https://mirrors.aliyun.com/anaconda/cloud/conda-forge/

2.2 新增 python 包

在 conda 环境激活状态下,使用 pip 安装 python 依赖包,可以配置国内镜像源:中科大、清华、阿里云

# 配置中科大pip镜像源
pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple
# 检查是否配置成功
pip config list

出现一下结果说明配置成功

global.index-url='https://pypi.mirrors.ustc.edu.cn/simple'

更新日志

  • 20250111: 初稿