Ubuntu 安装 Miniconda 及配置国内镜像源完整指南
目录
- Miniconda 安装
- Conda 镜像源配置
- Pip 镜像源配置
- 验证配置
- 基本使用
- 常见问题
1. Miniconda 安装
1.1 下载安装脚本
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
1.2 执行安装
bash Miniconda3-latest-Linux-x86_64.sh
- 按回车查看许可协议
- 输入 yes 同意协议
- 按回车使用默认安装路径(~/miniconda3)
- 输入 yes 初始化 Miniconda
1.3 激活安装
source ~/.bashrc
1.4 验证安装
conda --version
# 成功安装会显示版本号(如 conda 24.1.2)
2. Conda 镜像源配置
2.1 清华源配置(推荐)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes
3. pip镜像源配置
3.1 永久配置方法
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
4. 验证配置
4.1 验证conda源
conda config --show channels
4.2 验证pip源
pip config list
5. 基本使用
5.1 conda常用命令
# 创建环境
conda create -n myenv python=3.9# 激活环境
conda activate myenv# 安装包
conda install numpy# 导出环境
conda env export > environment.yml# 克隆环境
conda create --clone myenv --name myenv_copy
5.2 pip常用命令
# 安装包
pip install pandas# 批量安装
pip install -r requirements.txt# 生成依赖文件
pip freeze > requirements.txt
6. 常见问题
6.1 恢复默认源
# Conda
conda config --remove-key channels# Pip
pip config unset global.index-url
6.2 清理缓存
conda clean -a # 清理conda缓存
pip cache purge # 清理pip缓存
6.3 更新工具
conda update conda
pip install --upgrade pip
提示:建议定期运行 conda update --all 更新所有包。