@yangwenbo
2023-02-10T17:28:50.000000Z
字数 4638
阅读 235
清华大学-FIB实验室
#wget下载 Anaconda 安装脚本
root@7a927d2dc743:~# wget -P ./ https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.02-Linux-x86_64.sh
#检查包的完整性
root@7a927d2dc743:~# sha256sum Anaconda3-2020.02-Linux-x86_64.sh
2b9f088b2022edb474915d9f69a803d6449d5fdb4c303041f60ac4aefcc208bb Anaconda3-2020.02-Linux-x86_64.sh
#运行脚本启动安装进程
root@7a927d2dc743:~# sh Anaconda3-2020.02-Linux-x86_64.sh
#你应该能看到下面的输出:
Welcome to Anaconda3 2020.02
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
#按ENTER继续。往下滑动阅读协议,使用ENTER按键。一旦你看完协议,你将会被询问是否接受协议条款:
Do you accept the license terms? [yes|no]
[no] >>> yes
输入yes接受协议,并且你会被提示选择安装路径:
Anaconda3 will now be installed into this location:
/root/anaconda3 #这里是默认路径
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/anaconda3] >>> /usr/local/anaconda3 #可以在这里自定义新的的安装路径
#安装过程将会花费一些时间,并且一旦完成,脚本将会问你是否想要运行conda init。输入yes。
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
#这将会将命令行工具conda添加到系统的PATH环境变量中。
#想要激活 Anaconda,你可以关闭并且重新打开你的 shell 或者在当前 shell 会话中输入下面的命令,来重新加载PATH环境变量:
root@7a927d2dc743:~# source ~/.bashrc
#查看安装的版本
(base) root@7a927d2dc743:~# conda -V
conda 4.8.2
#添加清华源
(base) root@7a927d2dc743:~# conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
(base) root@7a927d2dc743:~# conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
(base) root@7a927d2dc743:~# conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
(base) root@7a927d2dc743:~# conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
(base) root@7a927d2dc743:~# conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
(base) root@7a927d2dc743:~# conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
#查看添加的清华源
(base) root@7a927d2dc743:~# conda config --show-sources
==> /root/.condarc <==
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
这里有一点就是,如果添加源之后发现还是搜索的默认源,可以将- defaults这一行删除就可以了。
#conda命令帮助
(base) root@7a927d2dc743:/# conda --help
(base) root@7a927d2dc743:/# conda --h
#查询某个命令的使用(--help均可以换成--h)
(base) root@7a927d2dc743:/# conda update --help
#查看环境管理的全部帮助命令
(base) root@7a927d2dc743:/# conda env -h
#创建一个基础环境
(base) root@7a927d2dc743:/# conda create --name test
#创建制定python版本的环境
(base) root@7a927d2dc743:/# conda create --name python-3.7 python=3.7
#创建指定python版本包含某些包的环境
(base) root@7a927d2dc743:/# conda create --name python-3.8 python=3.8 numpy scipy
#列举当前所有环境
(base) root@7a927d2dc743:/# conda env list
# conda environments:
#
base * /usr/local/anaconda3
python-3.7 /usr/local/anaconda3/envs/python-3.7
python-3.8 /usr/local/anaconda3/envs/python-3.8
test /usr/local/anaconda3/envs/test
(base) root@7a927d2dc743:/#
(base) root@7a927d2dc743:/# conda info --envs
# conda environments:
#
base * /usr/local/anaconda3
python-3.7 /usr/local/anaconda3/envs/python-3.7
python-3.8 /usr/local/anaconda3/envs/python-3.8
test /usr/local/anaconda3/envs/test
#进入一个环境
(base) root@7a927d2dc743:/# conda activate test
(test) root@7a927d2dc743:/#
#退出当前环境(这里会退到上个环境)
(test) root@7a927d2dc743:/# conda deactivate
(base) root@7a927d2dc743:/#
#复制某个环境为新环境
(base) root@7a927d2dc743:/# conda create --name test-2 --clone test
#公式
conda create --name new_your_env_name --clone old_your_env_name
#删除某个环境
(base) root@7a927d2dc743:/# conda remove --name test-2 --all
注意:请只用conda创建和管理环境,里面一切包用pip安装!!
#安装常用命令
(base) root@7a927d2dc743:/# pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ipython pandas pillow matplotlib setproctitle networkx scikit-learn scipy tqdm GPUtil jupyterlab notebook h5py statsmodels
#列举当前环境下所有包
(base) root@7a927d2dc743:/# conda list
#列举另外一个不活跃环境下所有包
(base) root@7a927d2dc743:/# conda list -n python-3.7
#为指定环境安装一个指定的包
(base) root@7a927d2dc743:/# conda install -n python-3.7 scipy
#检查刚安装的包
(base) root@7a927d2dc743:/# conda list -n python-3.7|grep scipy
scipy 1.7.3 py37hf2a6cf1_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
#python3.7环境
(base) root@7a927d2dc743:/# conda activate python-3.7
(python-3.7) root@7a927d2dc743:/# python
python python3 python3-config python3.7 python3.7-config python3.7m python3.7m-config
#python3.8环境(多了python3.8与python3.8-config)
(python-3.7) root@7a927d2dc743:/# conda activate python-3.8
(python-3.8) root@7a927d2dc743:/# python
python python3-config python3.7-config python3.7m-config python3.8-config
python3 python3.7 python3.7m python3.8