Qingquan-Li / blog

My Blog
https://Qingquan-Li.github.io/blog/
132 stars 16 forks source link

Linux 上安装 conda(miniconda) #133

Open Qingquan-Li opened 4 years ago

Qingquan-Li commented 4 years ago

环境:

参考:


因为 conda 包管理工具,本来就有很多依赖包,不能通过 $ pip install conda 进行安装,只能通过安装 AnacondaMiniconda 的形式进行安装。

Miniconda 是 conda 的最小安装程序。仅包含 conda,Python,及其依赖包,和少量常用的包。


# 把 miniconda 下载到 ~/Downloads 目录下。
# https://docs.conda.io/en/latest/miniconda.html
fatli@fatli-vm-ubuntu:~/Downloads$ wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
# 此时此处的版本为:Python 3.7, Miniconda Linux 64-bit
fatli@fatli-vm-ubuntu:~/Downloads$ ls
Miniconda3-latest-Linux-x86_64.sh

# 如果使用 wget 在线下载的方式太慢,可以在本地下载好 .sh 文件,再通过 scp 传输到服务器,实例:
$ scp /Users/fatli/Downloads/Miniconda3-latest-Linux-x86_64.sh ubuntu@129.204.83.148:~/Downloads

# 执行 miniconda 脚本进行
fatli@fatli-vm-ubuntu:~/Downloads$ bash Miniconda3-latest-Linux-x86_64.sh

Welcome to Miniconda3 4.7.12
# ...
# 基本上一直回车同意或输入yes即可。
# ...
# 提示:重启终端窗口后,conda即可生效。
==> For changes to take effect, close and re-open your current shell. <==

# 提示:打开终端会默认激活conda的base虚拟环境,可以设置为关闭。重启终端后生效。
If you'd prefer that conda's base environment not be activated on startup,
   set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

Thank you for installing Miniconda3!


重启终端后 conda 生效:

(base) fatli@fatli-vm-ubuntu:~$ conda -V
conda 4.7.12
(base) fatli@fatli-vm-ubuntu:~$ python
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Configure conda-forge channel (Optional)

References: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html https://conda-forge.org/

For example:

jake@ubuntu:~$ cat ~/.condarc
auto_activate_base: false
jake@ubuntu:~$ conda config --show-sources
==> /home/jake/.condarc <==
auto_activate_base: False

jake@ubuntu:~$ conda config --add channels conda-forge
jake@ubuntu:~$ conda config --show-sources
==> /home/jake/.condarc <==
auto_activate_base: False
channels:
  - conda-forge
  - defaults
jake@ubuntu:~$ conda config --set channel_priority strict


WSL2 Ubuntu 16.04 LTS 安装 Miniconda

参考:https://www.digitalocean.com/community/tutorials/how-to-install-the-anaconda-python-distribution-on-debian-10

参照上文安装 Miniconda ,

...
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> 

Type yes so that you do not need to add Miniconda to the PATH manually(手动).


激活 conda

You can now activate the installation by sourcing the ~/.bashrc file:

$ source ~/miniconda3/bin/activate