安装Anaconda

Linux

备注

安装运行环境是 FedoraUbuntu Linux

我在本文实践基础上,构建 Fedora镜像(采用tini替代systemd)Ubuntu镜像(采用tini替代systemd) 部署Anaconda

  • 下载Anaconda Installer并执行安装:

下载和运行Anaconda Installer
curl --output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2023.09-Linux-x86_64.sh

#curl --output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-aarch64.sh

chmod +x anaconda.sh
bash anaconda.sh

按照提示接受license并且按照默认执行 init 即可。默认安装在 $HOME/anaconda3 目录下:

Anaconda安装最后的init步骤,自动更新shell profile以便自动初始化conda
...
done
installation finished.
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
   run the following command when conda is activated:

conda config --set auto_activate_base false

You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes  <= 这里输入yes
no change     /home/admin/anaconda3/condabin/conda
no change     /home/admin/anaconda3/bin/conda
no change     /home/admin/anaconda3/bin/conda-env
no change     /home/admin/anaconda3/bin/activate
no change     /home/admin/anaconda3/bin/deactivate
no change     /home/admin/anaconda3/etc/profile.d/conda.sh
no change     /home/admin/anaconda3/etc/fish/conf.d/conda.fish
no change     /home/admin/anaconda3/shell/condabin/Conda.psm1
no change     /home/admin/anaconda3/shell/condabin/conda-hook.ps1
no change     /home/admin/anaconda3/lib/python3.11/site-packages/xontrib/conda.xsh
no change     /home/admin/anaconda3/etc/profile.d/conda.csh
modified      /home/admin/.bashrc

==> For changes to take effect, close and re-open your current shell. <==

Thank you for installing Anaconda3!
  • 再次登陆系统,或者直接执行:

    source ~/.bashrc
    

此时就进入了Anaconda的 Python virtualenv 就可以使用 conda 命令,例如 conda list 可以查看安装好的Anaconda包:

再次登陆到anaconda环境中可以看到 Python virtualenv 环境下可以使用 conda list 这样的命令
(base) [admin@fedora-ssh-tini ~]$ conda list
# packages in environment at /home/admin/anaconda3:
#
# Name                    Version                   Build  Channel
_anaconda_depends         2023.09         py311_openblas_1
_libgcc_mutex             0.1                        main
_openmp_mutex             5.1                      51_gnu
...

安装错误处理

我在 Ubuntu镜像(采用tini替代systemd) 环境部署 anaconda 时遇到报错:

Ubuntu镜像(采用tini替代systemd) 环境部署 Anaconda 报错
...
Anaconda3 will now be installed into this location:
/home/admin/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/home/admin/anaconda3] >>>
PREFIX=/home/admin/anaconda3
Unpacking payload ...

Installing base environment...


Downloading and Extracting Packages


Downloading and Extracting Packages

Preparing transaction: done
Executing transaction: \
done
ERROR conda.core.link:_execute(740): An error occurred while installing package 'defaults::ncurses-6.4-h419075a_0'.
Rolling back transaction: done

[Errno 17] File exists: 'Eterm' -> '/home/admin/anaconda3/share/terminfo/e/eterm-color'
(FileNotFoundError(2, 'No such file or directory'), FileNotFoundError(2, 'No such file or directory'), FileNotFoundError(2, 'No such file or directory'), FileNotFoundError(2, 'No such file or directory'))

这个问题在 Error related to ncurses-6.2 when installing conda on an Ubuntu server (16.04.7 LTS) #12089 有人已经指出了: 当在Docker中运行时,需要确保底层文件系统是和Linux一致的 区分大小写 文件系统。

我在 Docker Desktop for macOS 上部署 Ubuntu镜像(采用tini替代systemd) ,恰好就是将共享卷建立在 case insensitiveAPFS 上导致上述问题。解决方法是 macOS区分大小写APFS (通过新增APFS Container可以实现无需重装系统就隔离出一个区分大小写的卷)

GUI包

Anaconda的GUI软件包依赖Qt,在各大Linux发行版需要安装以下软件包:

  • Debian:

Debian发行版安装Anaconda的GUI依赖软件包
apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6
  • RedHat:

RedHat发行版安装Anaconda的GUI依赖软件包
yum install libXcomposite libXcursor libXi libXtst libXrandr alsa-lib mesa-libEGL libXdamage mesa-libGL libXScrnSaver
  • ArchLinux:

ArchLinux发行版安装Anaconda的GUI依赖软件包
pacman -Sy libxau libxi libxss libxtst libxcursor libxcomposite libxdamage libxfixes libxrandr libxrender mesa-libgl  alsa-lib libglvnd
  • OpenSuse/SLES:

OpenSuse/SLES发行版安装Anaconda的GUI依赖软件包
zypper install libXcomposite1 libXi6 libXext6 libXau6 libX11-6 libXrandr2 libXrender1 libXss1 libXtst6 libXdamage1 libXcursor1 libxcb1 libasound2  libX11-xcb1 Mesa-libGL1 Mesa-libEGL1
  • Gentoo:

Gentoo发行版安装Anaconda的GUI依赖软件包
emerge x11-libs/libXau x11-libs/libxcb x11-libs/libX11 x11-libs/libXext x11-libs/libXfixes x11-libs/libXrender x11-libs/libXi x11-libs/libXcomposite x11-libs/libXrandr x11-libs/libXcursor x11-libs/libXdamage x11-libs/libXScrnSaver x11-libs/libXtst media-libs/alsa-lib media-libs/mesa

macOS

Anaconda官方提供了 macOS 的 Intel 和 M1/M2 安装包( .pkg ) ,安装提供了 仅在当前用户下安装系统级别安装 两种方式。

更新

  • 在Anaconda环境中,可以对整个Anaconda系统更新:

更新Anaconda
conda update --all

参考