conda与pip的常用命令

conda的常用命令

1.查看conda版本
bash 复制代码
$ conda --version
conda 23.11.0
2.查看conda的配置信息
bash 复制代码
$ conda info

     active environment : base
    active env location : /home/myPc/miniconda3
            shell level : 1
       user config file : /home/myPc/.condarc
 populated config files : 
          conda version : 23.11.0
    conda-build version : not installed
         python version : 3.11.5.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=skylake
                          __conda=23.11.0=0
                          __cuda=12.2=0
                          __glibc=2.35=0
                          __linux=6.5.0=0
                          __unix=0=0
       base environment : /home/myPc/miniconda3  (writable)
      conda av data dir : /home/myPc/miniconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/myPc/miniconda3/pkgs
                          /home/myPc/.conda/pkgs
       envs directories : /home/myPc/miniconda3/envs
                          /home/myPc/.conda/envs
               platform : linux-64
             user-agent : conda/23.11.0 requests/2.31.0 CPython/3.11.5 Linux/6.5.0-17-generic ubuntu/22.04.3 glibc/2.35 solver/libmamba conda-libmamba-solver/23.12.0 libmambapy/1.5.3
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

上面我们可以得到几个比较重要的信息:

1、conda的配置文件

2、conda的env目录地址

3、conda安装时,采用的conda远程仓库地址

3.查看env环境
bash 复制代码
$ conda env list
# conda environments:
#
base                  *  /home/myPc/miniconda3
4.创建/激活/取消激活/删除一个新的环境
bash 复制代码
# 创建环境
$ conda create -n myEnv 
# 如何创建的同时,需要预安装依赖包,则可以这样: conda create -n myEnv tensorflow-gpu
# 若需要制定版本,如:conda create -n myEnv tensorflow-gpu=2.0

# 激活
$ conda activate myEnv

# 取消激活
$ conda deactivate myEnv

# 删除
$ conda env remove -n myEnv
5.搜索一个依赖包
bash 复制代码
$ conda search pytorch-cpu
Loading channels: done
# Name                       Version           Build  Channel             
pytorch-cpu                    1.2.0               0  pkgs/main           
pytorch-cpu                    1.3.1               0  pkgs/main           
pytorch-cpu                    2.1.0      h2657520_0  pkgs/main 
6.安装/删除一个依赖包
bash 复制代码
# 安装依赖包
$ conda install pytorch
# 指定版本安装依赖 conda install pytorch=2.1.0
# 也可采用通配 pytorch=2.*

# 删除一个依赖
$ conda remove pytorch
7.查看conda仓库地址
bash 复制代码
# 查看配置channels参数
$ conda config --show channels
# 也可以使用 conda info 命令
8.查conda的用户配置文件信息
bash 复制代码
# 直接查看.condarc文件
$ conda config --show-sources
==> /home/myPc/.condarc <==
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
show_channel_urls: True
9.配置conda的远程仓库地址
bash 复制代码
# 追加config配置参数
$ 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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r

# 设置config配置中的参数
$ conda config --set show_channel_urls yes

关于conda远程仓库的设置详细见这里

快速了解conda环境情况的步骤

1.step、查看conda环境conda env list

2.step、查看配置情况,了解当前基本配置conda infoconda config --show

3.step、查看当前环境已安装的所有依赖conda list

4.step、准备安装新的包

  • 4.0.step、添加镜像源conda config --add channels <url>
  • 4.1.step、搜索一下当前仓库配置下有什么版本的包conda search <packageName>
  • 4.2.step、安装依赖conda install <packageName>=<version>

pip常用命令

1.安装、删除依赖命令
bash 复制代码
# 安装包
$ pip install <packageName>
# 也可以指定版本: pip install <packageName>==<version>

# 删除包
$ pip uninstall <packageName>

指定安装源安装

bash 复制代码
pip install -i https://pypi.douban.com/simple/ package_name

查询指定包的可选版本号

如何查看指定依赖包的可选安装版本,安装依赖包时,只需要设置一个非常大的版本号,或者直接不设置就可以

bash 复制代码
$ pip install tensorflow-gpu==
ERROR: Could not find a version that satisfies the requirement tensorflow-gpu== (from versions: 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.6.0, 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5, 2.7.0rc0, 2.7.0rc1, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.8.0rc0, 2.8.0rc1, 2.8.0, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.9.0rc0, 2.9.0rc1, 2.9.0rc2, 2.9.0, 2.9.1, 2.9.2, 2.9.3, 2.10.0rc0, 2.10.0rc1, 2.10.0rc2, 2.10.0rc3, 2.10.0, 2.10.1, 2.11.0rc0, 2.11.0rc1, 2.11.0rc2, 2.11.0, 2.12.0)
ERROR: No matching distribution found for tensorflow-gpu==
2.设置pip远程镜像仓库地址

查看配置

bash 复制代码
$ pip config list
bash 复制代码
# 设置清华镜像仓
$ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
$ pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn

# 删除配置则
$ pip config unset install.trusted-host

或者直接写pip.conf文件

pip.ini文件所在的位置,一般在~/.config/pip/pip.conf

一下为设置阿里云的镜像

conf 复制代码
[global]
--index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
--trusted-host = mirrors.aliyun.com

收集的一些其他pip镜像仓库

# 阿里源
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com
 
# 豆瓣源
[global]
index-url=http://pypi.douban.com/simple/
trusted-host=pypi.douban.com
 
# 清华大学源
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
trusted-host=pypi.tuna.tsinghua.edu.cn
 
# 中国科技大学源
[global]
index-url=https://pypi.mirrors.ustc.edu.cn/simple/
trusted-host=pypi.mirrors.ustc.edu.cn
相关推荐
爱吃油淋鸡的莫何5 小时前
Conda新建python虚拟环境问题
开发语言·python·conda
Teleger2 天前
使用python来保存键盘输入情况,可保存到sqlite3数据库
python·conda
MonkeyKing_sunyuhua2 天前
Ubuntu 中无法直接使用 `conda` 命令,设置conda的环境变量
linux·ubuntu·conda
哆啦叮当3 天前
Linux下root用户共享conda环境给其他用户
linux·运维·服务器·python·conda
985小水博一枚呀4 天前
【深度学习|PyTorch】基于 PyTorch 搭建 U-Net 深度学习语义分割模型——附代码及其解释!
网络·人工智能·pytorch·python·深度学习·conda·numpy
chen_zn955 天前
conda常用指令
conda
AI浩8 天前
Conda和pip 清空缓存
conda·pip
技shu支持8 天前
PyCharm与Anaconda超详细安装配置教程
ide·python·pycharm·conda
SteveMiller10 天前
conda、anaconda、pip、torch、pytorch、tensorflow到底是什么东西?(转载自本人的知乎回答)
pytorch·conda·pip
深蓝海拓10 天前
新电脑安装和配置pytorch、anaconda、CUDA、cuDNN、pycharm的过程记录
人工智能·pytorch·python·pycharm·conda