Anaconda是什么
Anaconda是一个开源的Python和R语言发行版,专注于数据科学和科学计算,集成了conda包管理器、Python解释器及180多个科学计算库,提供环境管理和跨平台支持。
定义与核心特性
Anaconda是由Continuum Analytics(现Anaconda, Inc.)开发的科学计算平台,其核心包含以下组件:
Python/R解释器:提供基础编程语言支持。
Conda工具链:集成包管理(自动处理依赖关系)和环境管理(创建独立虚拟环境)功能。12
预装科学库:如NumPy、Pandas、Matplotlib等,覆盖数据分析、机器学习等领域。34
主要用途
数据科学与机器学习:预装工具库(如Scikit-learn、TensorFlow)简化模型开发流程。2
跨平台开发:支持Windows、macOS和Linux系统,确保环境一致性。4
项目管理:通过虚拟环境隔离不同项目的依赖版本,避免冲突。5
与Python的关系
Anaconda并非编程语言,而是基于Python的增强发行版:
扩展功能:在Python解释器基础上整合了包管理、环境隔离和预装库。3
简化部署:相比原生Python需手动安装库,Anaconda提供“开箱即用”体验。
Anaconda安装
1. 下载安装脚本
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh2. 执行安装
[root@localhost ctdi]# chmod +x Miniconda3-latest-Linux-x86_64.sh
[root@localhost ctdi]# bash Miniconda3-latest-Linux-x86_64.sh
中途会看到安装向导:
按 Enter 阅读许可协议(长篇内容可以直接按 q 跳过)
输入 yes 接受许可
选择安装路径(默认是 ~/miniconda3,直接回车即可)
提示是否初始化 conda → 推荐输入 yes
Welcome to Miniconda3 py313_25.7.0-2
...
Thank you for installing Miniconda3!
[root@localhost ctdi]# source ~/.bashrc
(base) [root@localhost ctdi]#
(base) [root@localhost ctdi]# conda -V
conda 25.7.0
(base) [root@localhost ctdi]# 3. 修改conda环境配置
由于初始化后conda默认进入base虚拟环境, 所以命令行前会出现(base)
编辑conda环境变量配置文件, 取消默认进入base环境, 修改源信息, 修改ssl证书
(base) [root@localhost ctdi]# vim ~/.condarc
# 写入内容如下
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
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
auto_activate: false
# centos系统使用这个
# ssl_verify: /etc/pki/tls/certs/ca-bundle.crt
# ubuntu系统使用这个
ssl_verify: /etc/ssl/certs/ca-certificates.crt
(base) [root@localhost ctdi]# source ~/.bashrc
# 此时重连ssh即可
[root@localhost ~]#
[root@localhost ~]# conda env list
# conda environments:
#
base /root/miniconda3
[root@localhost ~]# conda -V
conda 25.7.0
[root@localhost ~]# 4. 创建虚拟环境
zhangyunlong@matebook14s:~$ conda env list
# conda environments:
#
base /home/zhangyunlong/miniconda3
zhangyunlong@matebook14s:~$ conda create -n llama-factory python=3.10 pip
zhangyunlong@matebook14s:~$ conda env list
# conda environments:
#
base /home/zhangyunlong/miniconda3
llama-factory /home/zhangyunlong/miniconda3/envs/llama-factory
zhangyunlong@matebook14s:~$5. 激活虚拟环境
zhangyunlong@matebook14s:/opt/vllm/LLaMA-Factory$ conda activate llama-factory
(llama-factory) zhangyunlong@matebook14s:/opt/vllm/LLaMA-Factory$ 6. 退出虚拟环境
(llama-factory) zhangyunlong@matebook14s:~$ conda deactivate
zhangyunlong@matebook14s:~$7. 删除虚拟环境
zhangyunlong@matebook14s:~$ conda env list
# conda environments:
#
base /home/zhangyunlong/miniconda3
python-3.10 /home/zhangyunlong/miniconda3/envs/python-3.10
zhangyunlong@matebook14s:~$ conda env remove -n python-3.10
Remove all packages in environment /home/zhangyunlong/miniconda3/envs/python-3.10:
## Package Plan ##
environment location: /home/zhangyunlong/miniconda3/envs/python-3.10
The following packages will be REMOVED:
_libgcc_mutex-0.1-main
...
roceed ([y]/n)? y
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Everything found within the environment (/home/zhangyunlong/miniconda3/envs/python-3.10), including any conda environment configurations and any non-conda files, will be deleted. Do you wish to continue?
(y/[n])? y
zhangyunlong@matebook14s:~$ conda env list
# conda environments:
#
base /home/zhangyunlong/miniconda3
zhangyunlong@matebook14s:~$