安装miniconda

https://docs.conda.io/projects/miniconda/en/latest/

windows安装文件

期间有一个选择是否将conda加入path的选项,这里可以不选,安装完后,会有两个程序,要用的时候,选一个即可,如下所示


linux安装

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh

命令

创建虚拟环境

#创建名为env_name的虚拟环境,不指定Python版本(默认安装最新版本的Python)
conda create -n env_name
#创建名为env_name的虚拟环境,并指定Python版本为3.6.5
conda create -n env_name python=3.6.5

查看现有虚拟环境列表

conda env list

激活(选择)虚拟环境

# 需要先进入miniconda的环境,如果已经在则忽略这一步
C:/Users/admin/miniconda3/Scripts/activate
conda activate env_name 

退出虚拟环境

conda deactivate

删除虚拟环境

conda remove -n env_name --all 
# 也可以 conda remove --name env_name --all

导出环境配置

conda env export > environment.yml

如下样例

name: langchain-qianfan
channels:
  - defaults
dependencies:
  - bzip2=1.0.8=he774522_0
  - ca-certificates=2023.08.22=haa95532

导入环境配置

conda env create -f environment.yml
# 如上面样例,可修改name来指定新name

列出已安装的包

conda list

结果样例

# packages in environment at C:\Users\admin\miniconda3\envs\nanogpt:
#
# Name                    Version                   Build  Channel  
ca-certificates           2023.08.22           haa95532_0
certifi                   2023.7.22                pypi_0    pypi   
charset-normalizer        3.2.0                    pypi_0    pypi   
colorama                  0.4.6                    pypi_0    pypi   
filelock                  3.12.4                   pypi_0    pypi

清理包和缓存

# 清理包(不再使用的)
conda clean --packages

#清理缓存
conda clean --all


帮助命令

conda -h

结果

(nanogpt) E:\Xiang\Docs>conda -h  
usage: conda-script.py [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    clean             Remove unused packages and caches.
    compare           Compare packages between conda environments.
    config            Modify configuration values in .condarc. This is modeled after the git config command. Writes to the user .condarc file (C:\Users\admin\.condarc) by default. Use the   
                      --show-sources flag to display all identified configuration locations on your computer.
    create            Create a new conda environment from a list of specified packages.
    info              Display information about current conda install.
    init              Initialize conda for shell interaction.
    install           Installs a list of packages into a specified conda environment.
    list              List installed packages in a conda environment.
    package           Low-level conda package utility. (EXPERIMENTAL)
    remove (uninstall)
                      Remove a list of packages from a specified conda environment. Use `--all` flag to remove all packages and the environment itself.
    rename            Renames an existing environment.
    run               Run an executable in a conda environment.
    search            Search for packages and display associated information.The input is a MatchSpec, a query language for conda packages. See examples below.
    update (upgrade)  Updates conda packages to the latest compatible version.
    notices           Retrieves latest channel notifications.

options:
  -h, --help          Show this help message and exit.
  -V, --version       Show the conda version number and exit.

conda commands available from other packages:
 doctor - A subcommand that displays environment health report

conda commands available from other packages (legacy):
  content-trust
  env

参考:

https://blog.csdn.net/Mr_Dragon66/article/details/128277411

https://www.cnblogs.com/shukeshu/p/17516978.html