安装
先检查下机器有没有安装conda
conda --version
在这找到合适的版本
https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
或者https://docs.anaconda.com/free/miniconda/
复制链接
到机器上使用wget下载下载,
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
然后 bash Miniconda3-latest-Linux-x86_64.sh
一直回车,遇到选择就yes
安装完成后,
cd miniconda3/bin
pwd
#记录下这个位置,等会配置环境变量要用上
#如我这是`/root/miniconda3/bin`
执行 source ~/.bashrc
,
然后配置环境变量
vim /etc/profile
改成可编辑模式,添加如下内容
# 替换为自己机器的miniconda3的bin路径,如上pwd的结果
export PATH="/root/miniconda3/bin:$PATH"
然后 source /etc/profile
解决终端每次打开都进入conda的base环境的问题:(选择性执行)
conda config --set auto_activate_base false
更换 conda、pip、yum 国内源
建议使用ustc的源,依次执行:
conda ustc源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
# pip ustc源
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
# yum 国内源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum -y update
二、使用
- 创建一个虚拟环境
# 创建3.8 的虚拟环境,取名为python38
conda create -n python38 python=3.8
conda create -n env_name python=x.x --yes #这样就不用一直yes,直接安装了
- 进入到虚拟环境
# python38 为自己创建的环境名字
conda activate python38
conda activate en_name 或者 source activate env_name
- 退出当前的虚拟环境,执行:
conda deactivate python38
- 删除某个虚拟环境,执行:
conda remove -n python38 --all
- 删除所有的安装包及cache(索引缓存、锁定文件、未使用过的包和tar包)
conda clean -y --all
- 删除pip的缓存
rm -rf ~/.cache/pip
- 查看安装了哪些包
conda list
- 检查更新conda
conda update conda
- 查看当前存在哪些虚拟环境
conda env list 或者 conda info -e
- 进入虚拟环境后使用如下指令可以只在当前环境中安装删除包
conda install pkg_name
conda uninstall pkg_name
pip install pkg_name
pip uninstall pkg_name
- 查看所有配置信息
conda config --show --json