conda常用命令:安装,更新,创建,激活,关闭,查看,卸载,删除,清理,重命名,换源,问题

文章目录
安装
升级
卸载Anaconda软件
conda环境使用基本命令
查看指定包可安装版本信息命令
更新,卸载安装包:
删除虚拟环境
清理(conda瘦身)
复制/重命名/删除env环境
conda自动开启/关闭激活
Conda 安装本地包
解决conda/pip install 下载速度慢
conda数据源管理
pip数据源管理
pip安装包管理
pip和conda批量导出、安装组件(requirements.txt)
常用软件安装
问题
1:failed ERROR conda.core.link:_execute(502):
2.anaconda或conda不是内部命令
安装
linux环境

bash Anaconda3-2019.07-Linux-x86_64.sh
#yes+回车 
#然后重启terminal
1
2
3
window环境:直接双击安装exe文件,然后根据安装向导进行安装

升级
升级Anaconda需要先升级conda

conda update conda          #基本升级
conda update anaconda       #大的升级
conda update anaconda-navigator    //update最新版本的anaconda-navigator   
1
2
3
卸载Anaconda软件
由于Anaconda的安装文件都包含在一个目录中,所以直接将该目录删除即可。删除整个Anaconda目录:

计算机控制面板->程序与应用->卸载 //windows

或者

找到C:\ProgramData\Anaconda3\Uninstall-Anaconda3.exe执行卸载

rm -rf anaconda    //ubuntu
1
最后,建议清理下.bashrc中的Anaconda路径。

conda环境使用基本命令
conda update -n base conda        #update最新版本的conda
conda create -n xxxx python=3.5   #创建python3.5的xxxx虚拟环境
conda activate xxxx               #开启xxxx环境
conda deactivate                  #关闭环境
conda env list                    #显示所有的虚拟环境
conda info --envs                 #显示所有的虚拟环境
1
2
3
4
5
6
查看指定包可安装版本信息命令
参考:https://blog.csdn.net/qq_35203425/article/details/79965389
查看tensorflow各个版本:(查看会发现有一大堆TensorFlow源,但是不能随便选,选择可以用查找命令定位)

anaconda search -t conda tensorflow  
1
查看指定包可安装版本信息命令

anaconda show <USER/PACKAGE>  
1
查看指定anaconda/tensorflow版本信息

anaconda show tensorflow
1
输出结果会提供一个下载地址,使用下面命令就可指定安装1.8.0版本tensorflow

conda install --channel https://conda.anaconda.org/anaconda tensorflow=1.8.0 
1
更新,卸载安装包:
conda list         #查看已经安装的文件包
conda list  -n xxx       #指定查看xxx虚拟环境下安装的package
conda update xxx   #更新xxx文件包
conda uninstall xxx   #卸载xxx文件包
1
2
3
4
删除虚拟环境
conda remove -n xxxx --all   //创建xxxx虚拟环境
1
清理(conda瘦身)
conda clean就可以轻松搞定!第一步:通过conda clean -p来删除一些没用的包,这个命令会检查哪些包没有在包缓存中被硬依赖到其他地方,并删除它们。第二步:通过conda clean -t可以将删除conda保存下来的tar包。

conda clean -p      //删除没有用的包
conda clean -t      //删除tar包
conda clean -y --all //删除所有的安装包及cache
1
2
3
参考:https://blog.csdn.net/menc15/article/details/71477949

复制/重命名/删除env环境
Conda是没有重命名环境的功能的, 要实现这个基本需求, 只能通过愚蠢的克隆-删除的过程。
切记不要直接mv移动环境的文件夹来重命名, 会导致一系列无法想象的错误的发生!

//克隆oldname环境为newname环境
conda create --name newname --clone oldname 
//彻底删除旧环境
conda remove --name oldname --all      
1
2
3
4
注意:必须在base环境下进行以上操作,否则会出现各种莫名的问题。

conda自动开启/关闭激活
参考:https://www.cnblogs.com/clemente/p/11231539.html

conda activate   #默认激活base环境
conda activate xxx  #激活xxx环境
conda deactivate #关闭当前环境
conda config --set auto_activate_base false  #关闭自动激活状态
conda config --set auto_activate_base true  #关闭自动激活状态
1
2
3
4
5
Conda 安装本地包
有时conda或pip源下载速度太慢,install a过程中会中断连接导致压缩包下载不全,
此时,我们可以用浏览器等工具先下载指定包再用conda或pip进行本地安装

#pip 安装本地包
pip install   ~/Downloads/a.whl
#conda 安装本地包
conda install --use-local  ~/Downloads/a.tar.bz2
1
2
3
4
解决conda/pip install 下载速度慢
conda数据源管理
#显示目前conda的数据源有哪些
conda config --show channels
#添加数据源:例如, 添加清华anaconda镜像:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
#删除数据源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
1
2
3
4
5
6
7
8
记录一下

#本人的 ~/.condarc
auto_activate_base: false
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - 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/
show_channel_urls: true
1
2
3
4
5
6
7
8
9
10
11
pip数据源管理
#显示目前pip的数据源有哪些
pip config list
pip config list --[user|global] # 列出用户|全局的设置
pip config get global.index-url # 得到这key对应的value 如:https://mirrors.aliyun.com/pypi/simple/

# 添加
pip config set key value
#添加数据源:例如, 添加USTC中科大的源:
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
#添加全局使用该数据源
pip config set global.trusted-host https://mirrors.ustc.edu.cn/pypi/web/simple

# 删除
pip config unset key
# 例如
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

#搜索
pip search flask  #搜素flask安装包

# 升级pip
pip install pip -U
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
记录一下pip国内源

阿里云                    http://mirrors.aliyun.com/pypi/simple/
中国科技大学         https://pypi.mirrors.ustc.edu.cn/simple/ 
豆瓣(douban)         http://pypi.douban.com/simple/ 
清华大学                https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学  http://pypi.mirrors.ustc.edu.cn/simple/
1
2
3
4
5
pip安装包管理
pip list #列出当前缓存的包
pip purge #清除缓存
pip remove #删除对应的缓存
pip help #帮助
pip install xxx #安装xxx包
pip uninstall xxx #删除xxx包
pip show xxx #展示指定的已安装的xxx包
pip check xxx #检查xxx包的依赖是否合适
1
2
3
4
5
6
7
8
pip和conda批量导出、安装组件(requirements.txt)
参考

常用软件安装
参考:conda环境下常用软件安装

问题
1:failed ERROR conda.core.link:_execute(502):
conda install 软件时出现如下错误信息:
Preparing transaction: done
Verifying transaction: done
Executing transaction: 
failed ERROR conda.core.link:_execute(502):
1
2
3
4
5
解决方法:往往时权限不够,需要以管理员方式运行Anaconda prompt进行安装

2.anaconda或conda不是内部命令
解决方法:https://zhuanlan.zhihu.com/p/32446675

添加上图环境变量即可

jupyter notebook默认工作目录设置
参考:https://blog.csdn.net/liwei1205/article/details/78818568

1)在Anaconda Prompt终端中输入下面命令,查看你的notebook配置文件在哪里:

jupyter notebook --generate-config
#会生成文件C:\Users\用户\.jupyter\jupyter_notebook_config.py
1
2
2)打开jupyter_notebook_config.py文件通过搜索关键词:c.NotebookApp.notebook_dir,修改如下

c.NotebookApp.notebook_dir = 'E:\\tf_models'     //修改到自定义文件夹
1
3)然后重启notebook服务器就可以了

**注:**其它方法直接命令到指定目录,Anaconda Prompt终端中输:jupyter notebook 目录地址
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值