有一种奇妙的需求是,实验室某一台服务器需要装conda,既要保证其他用户能正常创建环境以及使用,又要让这些环境共有。
如果是这种情况,可以跟着本篇教程做。
如果仅为当前帐号安装的话,本教程兼容为当前帐号安装的情况。在sudo bash Anaconda3-2022.05-Linux-x86_64.sh部分都不用加sudo,然后配置完环境变量, init之后就可以使用了。
在anaconda官网上下载anaconda安装包,国内可以在清华镜像上找到,但不知道镜像网站能维持多久,因为近期docker已经被关停了。
PS: 这里不建议下最新版的,因为可能存在不能创建低版本python环境的风险。这里我下载的是Anaconda3-2022.05-Linux-x86_64.sh
打开terminal,然后进入到对应目录:
sudo bash Anaconda3-2022.05-Linux-x86_64.sh
在页面输入enter,然后出现服务条款,按q,然后输入yes回车
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
==================================================
Copyright 2015-2022, Anaconda, Inc.
All rights reserved under the 3-clause BSD License:
This End User License Agreement (the "Agreement") is a legal agreement between y
ou and Anaconda, Inc. ("Anaconda") and governs your use of Anaconda Distribution
(which was formerly known as Anaconda Individual Edition).
Subject to the terms of this Agreement, Anaconda hereby grants you a non-exclusi
ve, non-transferable license to:
* Install and use the Anaconda Distribution (which was formerly known as Anaco
nda Individual Edition),
* Modify and create derivative works of sample source code delivered in Anacon
da Distribution from Anaconda's repository, and;
* Redistribute code files in source (if provided to you by Anaconda as source)
and binary forms, with or without modification subject to the requirements set
forth below, and;
Do you accept the license terms? [yes|no]
[no] >>> yes
然后放需要放的地方,默认是/root/anaconda3,这个位置不太好,因为其他用户没有权限访问,可以改成/opt/anaconda3之类的大家可以公共访问的
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> no
这里不初始化,然后用你的编辑器打开~/.bashrc,在最后一行加上
export PATH=/opt/anaconda3/bin:$PATH
然后开始写初始化代码,其他用户同样也需要这个步骤:
/opt/anaconda3/bin/conda shell.bash hook >> ~/.bashrc
导入环境变量以及初始化,最后在terminal键入
source ~/.bashrc
接着装环境和lib可能会挺慢的,只能借助国内镜像,在conda和pip上设置镜像源(此处省略步骤)
创建一个环境:
conda create -n py38 python=3.8
名为py38试试看
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate py38
#
# To deactivate an active environment, use
#
# $ conda deactivate
OKOK,然后依照他的提示输入conda activate py38,即可
之后会讲解如何在环境上安装有GPU cuda的python库pytorch