CentOS7安装Miniconda
1. 物料包
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda
| 操作系统和芯片架构 | 文件 |
|---|---|
| MacOS Intel Chip | Miniconda3-latest-MacOSX-x86_64.sh |
| MacOS Apple Silicon | Miniconda3-latest-MacOSX-arm64.sh |
| Linux x86_64 | Miniconda3-latest-Linux-x86_64.sh |
| Linux aarch64 | Miniconda3-latest-Linux-aarch64.sh |
| Windows x86_64 | Miniconda3-latest-Windows-x86_64.exe |
类似产品:
- https://github.com/conda-forge/miniforge
2. 安装
[yangyunhe@sdp Downloads]$ sh Miniconda3-latest-Linux-x86_64.shWelcome to Miniconda3 py312_25.1.1-2In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue # 按下回车,浏览用户协议,一直按回车
>>>
ANACONDA TERMS OF SERVICE
...
1. ACCESS & USE
...
2. USERS & LICENSING
...
3. ANACONDA OFFERINGS
...
4. OPEN SOURCE, CONTENT & APPLICATIONS
...
5. CUSTOMER CONTENT, APPLICATIONS & RESPONSIBILITIES
...
6. YOUR DATA, PRIVACY & SECURITY
...
7. SUPPORT
...
8. OWNERSHIP & INTELLECTUAL PROPERTY
...
9. CONFIDENTIAL INFORMATION
...
10. INDEMNIFICATION
...
11. LIMITATION OF LIABILITY
...
12. FEES & PAYMENT
...
13. TERM, TERMINATION & SUSPENSION
...
14. RECORDS, USER COUNT
...
15. GENERAL PROVISIONS
...
16. DEFINITIONS
...
Do you accept the license terms? [yes|no] # 是否同意协议,输入 yes
>>> Please answer 'yes' or 'no':'
>>> yesMiniconda3 will now be installed into this location:
/home/yangyunhe/miniconda3- Press ENTER to confirm the location # 回车确认默认的路径:/home/yangyunhe/miniconda3- Press CTRL-C to abort the installation # CTRL-C 退出安装- Or specify a different location below # 输入安装路径[/home/yangyunhe/miniconda3] >>> # 默认安装的用户 home 目录下,敲回车确认,这里可以手动输入一个其他路径
PREFIX=/home/yangyunhe/miniconda3
Unpacking payload ...Installing base environment... # 安装基础环境
...... installation finished.
Do you wish to update your shell profile to automatically initialize conda? # 是否初始化 conda,输入 yes,否则 conda 无法正常使用
This will activate conda on startup and change the command prompt when activated. # 初始化之后,系统开机后就会激活 conda 并且会改变命令提示符
If you'd prefer that conda's base environment not be activated on startup, # 如果不需要在系统启动之后激活 base 环境,那么在 conda 激活后执行以下命令run the following command when conda is activated:conda config --set auto_activate_base falseYou can undo this by running `conda init --reverse $SHELL`? [yes|no] # 你可以通过执行此命令来退回 conda 初始化操作
[no] >>> yes # 输入 yes
...
Thank you for installing Miniconda3![yangyunhe@sdp Downloads]$# 再次连接终端,命令提示符会改变,base 代表目前的 python 环境是 base
(base) [yangyunhe@sdp ~]$
3. 虚拟环境操作
miniconda 是为当前用户安装的,conda 初始化之后,修改了用户的 .bashrc 文件
if [ $? -eq 0 ]; theneval "$__conda_setup"
elseif [ -f "/home/yangyunhe/miniconda3/etc/profile.d/conda.sh" ]; then. "/home/yangyunhe/miniconda3/etc/profile.d/conda.sh"elseexport PATH="/home/yangyunhe/miniconda3/bin:$PATH"fi
fi
unset __conda_setup
# 查看 python 版本
(base) [yangyunhe@sdp ~]$ python -V
Python 3.12.9# 创建虚拟环境
(base) [yangyunhe@sdp ~]$ conda create -n testenv python=3.11
# 激活虚拟环境
(base) [yangyunhe@sdp ~]$ conda activate testenv
(testenv) [yangyunhe@sdp ~]$# 查看 python 版本
(testenv) [yangyunhe@sdp ~]$ python -V
Python 3.11.11# 查看现有的环境(* 代表目前生效的环境)
(testenv) [yangyunhe@sdp lib]$ conda env list# conda environments:
#
base /home/yangyunhe/miniconda3
testenv * /home/yangyunhe/miniconda3/envs/testenv# 切换环境
(testenv) [yangyunhe@sdp ~]$ conda activate base
(base) [yangyunhe@sdp ~]$# 退出所有 miniconda 环境,返回系统的 python 版本
(base) [yangyunhe@sdp ~]$ conda deactivate
[yangyunhe@sdp ~]$
[yangyunhe@sdp ~]$ python -V
Python 2.7.5# 删除环境
[yangyunhe@sdp ~]$ conda env remove -n testenv# 设置不自动启用 base 环境
[yangyunhe@sdp ~]$ conda config --set auto_activate_base false
4. conda 设置清华大学源
https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
~/.condarc 文件
channels:- defaults
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/cloudpytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
anaconda_channels:- https://repo.anaconda.com/pkgs/main- https://repo.anaconda.com/pkgs/r
auto_activate_base: false
show_channel_urls: true
测试
# .condarc 有两个文件,/home/${user}/.condarc 和 /home/${user}/miniconda3/.condarc
# 都得修改,可以删除 /home/${user}/miniconda3/.condarc
(base) [yangyunhe@sdp ~]$ cp /home/yangyunhe/miniconda3/.condarc /home/yangyunhe/miniconda3/.condarc.bak
(base) [yangyunhe@sdp ~]$ rm -f /home/yangyunhe/miniconda3/.condarc
# 查看源
(base) [yangyunhe@sdp ~]$ conda config --show-sources
==> /home/yangyunhe/.condarc <==
channels:- defaults
custom_channels:conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloudpytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
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
show_channel_urls: True# 清除索引环境
(base) [yangyunhe@sdp ~]$ conda clean -i
Will remove 1 index cache(s).
Proceed ([y]/n)? y# 安装常用包测试
conda create -n myenv numpy# 删除测试环境
(base) [yangyunhe@sdp ~]$ conda env remove -n myenv
5 pip 设置清华大学源
修改 ~/.pip/pip.conf文件
[yangyunhe@sdp miniconda3]$ mkdir -p ~/.pip
[yangyunhe@sdp miniconda3]$ vim ~/.pip/pip.conf[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn# 校验
[yangyunhe@sdp miniconda3]$ ~/miniconda3/bin/pip config list
global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
install.trusted-host='pypi.tuna.tsinghua.edu.cn'