Conda 命令

1.更新

#获取版本号

复制代码
conda --version 或 conda -V
conda update conda          # 基本升级
conda update anaconda       # 大的升级
conda update anaconda-navigator    #update最新版本的anaconda-navigator

2.卸载

Anaconda的安装文件都包含在一个目录中,直接将该目录删除即可。

复制代码
rm -rf anaconda    #linux系统/windows系统类似

Linux系统下建议将.bashrc中的Anaconda路径也删掉

3.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                 #显示所有的虚拟环境

4.查看某个包的可安装版本信息

复制代码
anaconda search -t conda tensorflow  
anaconda show tensorflow

上面得出的会有一个下载地址,通过下面

复制代码
conda install --channel https://conda.anaconda.org/anaconda tensorflow=1.8.0   # 通过指定的渠道安装特定的版本

5.更新,卸载安装包

复制代码
conda list         #查看已安装的包
conda list  -n xxx       #指定查看xxx虚拟环境下安装的包
conda update xxx   #更新xxx包 
conda uninstall xxx   #卸载xxx包

6.删除虚拟环境

复制代码
conda remove -n xxxx --all   #删除xxxx虚拟环境

7.删除虚拟环境

复制代码
conda clean -p      #删除没有用的包 
conda clean -t      #删除无用的tar包 
conda clean -y --all #删除所有的安装包及cache

8.复制/重命名/删除env环境 **(**不能直接mv,下面操作必须在base上进行)

复制代码
#克隆oldname环境为newname环境 
conda create --name newname --clone oldname  
#彻底删除旧环境 
conda remove --name oldname --all

9.复制/重命名/删除env环境

复制代码
conda activate xxx  #激活xxx环境
conda deactivate #关闭当前环境
conda config --set auto_activate_base false  #关闭自动激活状态
conda config --set auto_activate_base true  #关闭自动激活状态

10.通过下载后本地安装包

复制代码
#pip 安装本地包 
pip install   ~/Downloads/a.whl 
#conda 安装本地包 
conda install --use-local  ~/Downloads/a.tar.bz2

11.conda和pip的数据源管理 conda(也可以直接修改~/.condarc文件)**

#显示目前conda的数据源有哪些

复制代码
conda config --show channels

#添加数据源:如清华源

复制代码
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/

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

---总结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/

12.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包的依赖是否合适

13.pip和conda批量导出和安装requirements.txt

复制代码
pip freeze > requirements.txt  # 导出
pip install -r requirements.txt  #安装
conda list -e > requirements.txt # 导出
conda install --yes --file requirements.txt #安装

14.pip命令的一些补充

复制代码
which pip   # 查看使用的是哪一个pip
pip -V     #查看pip的版本

3.实例:创建一个虚拟环境,且指定版本

复制代码
# 创建版本为2.7的名为venv27
conda create --name venv27 python=2.7
# 查看已有的虚拟环境
conda env list
# 进入venv27虚拟环境
conda activate venv27
# 查看python版本
python -V
# 退出此虚拟环境(默认进去base环境)
conda deactivate
# 退出base 环境 到达点击默认环境
conda deactivate

4.使用场景

若开发中需要应用到python2和python3的话,使用condo进行创建虚拟环境,可以指定解释器的版本,避免了一台电脑安装两个python解释器,两个pip。且方便进行切换解释器的版本。

A&Q

​ 1.若在创建虚拟环境时,报错

复制代码
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/osx-64/python-3.6.13-h88f2d9e_0.conda>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
相关推荐
老兵发新帖2 小时前
Ubuntu 上安装 Conda
linux·ubuntu·conda
一眼青苔4 小时前
python环境使用conda,conda如何升级默认的python版本
开发语言·python·conda
skywalk81635 小时前
Graph Database Self-Managed Neo4j 知识图谱存储实践2:通过官方新手例子入门(未完成)
数据库·知识图谱·neo4j
biter008813 小时前
ubuntu(28):ubuntu系统多版本conda和多版本cuda共存
linux·人工智能·ubuntu·conda
内网渗透13 小时前
Python 虚拟环境管理:venv 与 conda 的选择与配置
开发语言·python·conda·虚拟环境·venv
2501_9153743514 小时前
如何配置 Conda 使用镜像源加速
conda
2501_915374352 天前
使用 Conda 创建新环境
conda
程序员黄同学3 天前
AI 模型在前端应用中的典型使用场景和限制
前端·人工智能·neo4j