conda 学习记录
准备进军具身智能方向了,先从使用 conda 环境开始入手,虽然已经学习了一段时间了,但是还是想系统梳理一遍 conda 用法,借此机会来系统回忆一遍,欢迎各位大佬进行补充!
1 Conda 简介
略,此处不废话了...
2 安装
2.1 下载 Anaconda 安装包
下载链接:https://repo.anaconda.com/archive/
2.2 运行安装程序
1️⃣ 赋予执行权限
chmod +x Anaconda3-2024.10-1-Linux-x86_64.sh2️⃣ 启动安装
root@61acef4a23aa:~/private/package# ./Anaconda3-2025.06-0-Linux-x86_64.sh Welcome to Anaconda3 2025.06-0 In order to continue the installation process, please review the license agreement. Please, press ENTER to continue >>> By continuing installation, you hereby consent to the Anaconda Terms of Service available at https://anaconda.co m/legal. Do you accept the license terms? [yes|no] >>> yes Anaconda3 will now be installed into this location: /root/anaconda3 - Press ENTER to confirm the location - Press CTRL-C to abort the installation - Or specify a different location below Note: environment variables will NOT be expanded. [/root/anaconda3] >>> PREFIX=/root/anaconda3 Unpacking payload ... entry_point.py:256: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior. entry_point.py:256: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior. Installing base environment... Downloading and Extracting Packages: ## Package Plan ## environment location: /root/anaconda3 added / updated specs: - defaults/linux-64::_anaconda_depends==2025.06=py313_mkl_2[md5=8dd0a428197e12329e80d54846c1ad1b] - defaults/linux-64::_libgcc_mutex==0.1=main[md5=c3473ff8bdb3d124ed5ff11ec380d6f9] ...... Downloading and Extracting Packages: Preparing transaction: done Executing transaction: done entry_point.py:256: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior. installation finished. Do you wish to update your shell profile to automatically initialize conda? This will activate conda on startup and change the command prompt when activated. If you'd prefer that conda's base environment not be activated on startup, run the following command when conda is activated: conda config --set auto_activate_base false You can undo this by running `conda init --reverse $SHELL`? [yes|no] [no] >>> yes no change /root/anaconda3/condabin/conda no change /root/anaconda3/bin/conda no change /root/anaconda3/bin/conda-env no change /root/anaconda3/bin/activate no change /root/anaconda3/bin/deactivate no change /root/anaconda3/etc/profile.d/conda.sh no change /root/anaconda3/etc/fish/conf.d/conda.fish no change /root/anaconda3/shell/condabin/Conda.psm1 no change /root/anaconda3/shell/condabin/conda-hook.ps1 no change /root/anaconda3/lib/python3.13/site-packages/xontrib/conda.xsh no change /root/anaconda3/etc/profile.d/conda.csh modified /root/.bashrc ==> For changes to take effect, close and re-open your current shell. <== Thank you for installing Anaconda3!注意:
- 安装目录位置,最好采用默认位置/root/anaconda3,这样 conda init、PATH、激活环境都更稳定。
- "You can undo this by running `conda init --reverse $SHELL`? [yes|no]" 这部分是说,每次启动终端就自动激活(base)环境,输入
yes就是同意自动激活了。如果后期想不自动激活,可以在命令行输入:codna config --set auto_activate_base false,然后重启 bash 即可关闭自动激活。
2.3 初始化
有时候安装完成后不会自动初始化,此时要调用:
/root/anaconda3/bin/conda init即可完成初始化!
3 使用
3.0 conda -h
先从 conda -h 来看:
root@c25ff0eca7ce:~/private/transformers_learning# conda -h usage: conda [-h] [-v] [--no-plugins] [-V] COMMAND ... conda is a tool for managing and deploying applications, environments and packages. options: -h, --help Show this help message and exit. -v, --verbose Can be used multiple times. Once for detailed output, twice for INFO logging, thrice for DEBUG logging, four times for TRACE logging. --no-plugins Disable all plugins that are not built into conda. -V, --version Show the conda version number and exit. commands: The following built-in and plugins subcommands are available. COMMAND activate Activate a conda environment. build Build conda packages from a conda recipe. clean Remove unused packages and caches. commands List all available conda subcommands (including those from plugins). Generally only used by tab-completion. compare Compare packages between conda environments. config Modify configuration values in .condarc. content-trust Signing and verification tools for Conda convert Convert pure Python packages to other platforms (a.k.a., subdirs). create Create a new conda environment from a list of specified packages. deactivate Deactivate the current active conda environment. debug Debug the build or test phases of conda recipes. develop Install a Python package in 'development mode'. Similar to `pip install --editable`. doctor Display a health report for your environment. env Create and manage conda environments. export Export a given environment index Update package index metadata files. info Display information about current conda install. init Initialize conda for shell interaction. inspect Tools for inspecting conda packages. install Install a list of packages into a specified conda environment. list List installed packages in a conda environment. metapackage Specialty tool for generating conda metapackage. notices Retrieve latest channel notifications. pack See `conda pack --help`. package Create low-level conda packages. (EXPERIMENTAL) remove (uninstall) Remove a list of packages from a specified conda environment. rename Rename an existing environment. render Expand a conda recipe into a platform-specific recipe. repo See `conda repo --help`. repoquery Advanced search for repodata. run Run an executable in a conda environment. search Search for packages and display associated information using the MatchSpec format. server See `conda server --help`. skeleton Generate boilerplate conda recipes. token See `conda token --help`. tos A subcommand for viewing, accepting, rejecting, and otherwise interacting with a channel's Terms of Service (ToS). This plugin periodically checks for updated Terms of Service for the active/selected channels. Channels with a Terms of Service will need to be accepted or rejected prior to use. Conda will only allow package installation from channels without a Terms of Service or with an accepted Terms of Service. Attempting to use a channel with a rejected Terms of Service will result in an error. update (upgrade) Update conda packages to the latest compatible version.比较重要的就是 create、activate、config、deactivate、env、info、install、remove 几个,后续会慢慢介绍......
还有几个 options,用法:
1️⃣ 查看 conda 版本:
conda --version 输出:conda 25.5.12️⃣查看帮助:
conda -h 输出:上面的那些3.1 创建虚拟环境
conda create -n <env-name>例如:
conda create -n myenvironment此外,环境名字后面还可以跟需要安装的 package,即:创建环境的同时安装这些 packages,命令为:
conda create -n myenvironment python numpy pandas同时,每个包的后面还可以跟具体的版本号(不指定版本号时默认安装最新版本),如:
conda create -n myenvironment python=3.10 numpy pandas conda create -n myenvironment python==3.10 numpy pandas注意:python=3.10 和 python==3.10 是不一样的,两个==是明确具体版本号的意思,一个=好像是安装3.10.x系列中最新的,或者是最稳定的,这个不太确定!
一般创建的时候会指定 python 版本,也就是:conda create -n my_env python=3.10,这就是最常用的了。
3.2 激活虚拟环境
下面均以命令:
conda create -n myenv python=3.10为例进行讲解,示例输出如下:
root@c25ff0eca7ce:~/private/transformers_learning# conda create -n myenv python=3.10 2 channel Terms of Service accepted Channels: - defaults Platform: linux-64 Collecting package metadata (repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 25.5.1 latest version: 26.3.2 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: /root/anaconda3/envs/myenv added / updated specs: - python=3.10 The following packages will be downloaded: package | build ---------------------------|----------------- ca-certificates-2026.3.19 | h06a4308_0 126 KB packaging-26.0 | py310h06a4308_0 165 KB pip-26.0.1 | pyhc872135_1 1.1 MB setuptools-82.0.1 | py310h06a4308_0 1.2 MB tzdata-2026a | he532380_0 117 KB ------------------------------------------------------------ Total: 2.7 MB The following NEW packages will be INSTALLED: _libgcc_mutex pkgs/main/linux-64::_libgcc_mutex-0.1-main _openmp_mutex pkgs/main/linux-64::_openmp_mutex-5.1-1_gnu bzip2 pkgs/main/linux-64::bzip2-1.0.8-h5eee18b_6 ca-certificates pkgs/main/linux-64::ca-certificates-2026.3.19-h06a4308_0 expat pkgs/main/linux-64::expat-2.7.1-h6a678d5_0 ld_impl_linux-64 pkgs/main/linux-64::ld_impl_linux-64-2.40-h12ee557_0 libffi pkgs/main/linux-64::libffi-3.4.4-h6a678d5_1 libgcc-ng pkgs/main/linux-64::libgcc-ng-11.2.0-h1234567_1 libgomp pkgs/main/linux-64::libgomp-11.2.0-h1234567_1 libstdcxx-ng pkgs/main/linux-64::libstdcxx-ng-11.2.0-h1234567_1 libuuid pkgs/main/linux-64::libuuid-1.41.5-h5eee18b_0 libxcb pkgs/main/linux-64::libxcb-1.17.0-h9b100fa_0 libzlib pkgs/main/linux-64::libzlib-1.3.1-hb25bd0a_0 ncurses pkgs/main/linux-64::ncurses-6.5-h7934f7d_0 openssl pkgs/main/linux-64::openssl-3.0.17-h5eee18b_0 packaging pkgs/main/linux-64::packaging-26.0-py310h06a4308_0 pip pkgs/main/noarch::pip-26.0.1-pyhc872135_1 pthread-stubs pkgs/main/linux-64::pthread-stubs-0.3-h0ce48e5_1 python pkgs/main/linux-64::python-3.10.18-h1a3bd86_0 readline pkgs/main/linux-64::readline-8.3-hc2a1206_0 setuptools pkgs/main/linux-64::setuptools-82.0.1-py310h06a4308_0 sqlite pkgs/main/linux-64::sqlite-3.50.2-hb25bd0a_1 tk pkgs/main/linux-64::tk-8.6.15-h54e0aa7_0 tzdata pkgs/main/noarch::tzdata-2026a-he532380_0 wheel pkgs/main/linux-64::wheel-0.46.3-py310h06a4308_0 xorg-libx11 pkgs/main/linux-64::xorg-libx11-1.8.12-h9b100fa_1 xorg-libxau pkgs/main/linux-64::xorg-libxau-1.0.12-h9b100fa_0 xorg-libxdmcp pkgs/main/linux-64::xorg-libxdmcp-1.1.5-h9b100fa_0 xorg-xorgproto pkgs/main/linux-64::xorg-xorgproto-2024.1-h5eee18b_1 xz pkgs/main/linux-64::xz-5.6.4-h5eee18b_1 zlib pkgs/main/linux-64::zlib-1.3.1-hb25bd0a_0 Proceed ([y]/n)? y Downloading and Extracting Packages: Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use # # $ conda activate myenv # # To deactivate an active environment, use # # $ conda deactivate最后几行中,是提示如何激活此时创建的虚拟环境,这点还挺贴心的!还有安装的 python 版本是3.10.18,然后直接复制命令:
conda activate myenv用户名前面会变成:
(myenv) root@c25ff0eca7ce:~/private/transformers_learning#这样就激活 myenv 的虚拟环境了,然后,就可以安装 packages,来当牛马了!
3.3 安装 package
安装包的方式有两种,一种是用pip install,一种是conda install。
3.3.1 pip install <package-name>
# 不加版本号默认安装最新版 pip install numpy # 安装指定版本号 pip install numpy=2.2.03.3.2 conda install <package-name>
# 安装最新版 conda install matplotlib # 安装特定版本 conda install matplotlib==3.8.4####################### 先到这里 #######################
