管理 Python#

Managing Python

Conda 将 Python 视为与其他软件包相同的实体,因此可以轻松管理和更新多个安装版本。

Conda 支持 Python 3.9、3.10、3.11 和 3.12。

Conda treats Python the same as any other package, so it is easy to manage and update multiple installations.

Conda supports Python 3.9, 3.10, 3.11 and 3.12.

查看可用的 Python 版本列表#

Viewing a list of available Python versions

要列出可供安装的 Python 版本,请在终端窗口中运行:

conda search python

该命令会列出所有名称中包含 python 的软件包。

若只想列出名称完全为 python 的软件包,请添加 --full-name 选项。在终端窗口中运行:

conda search --full-name python

To list the versions of Python that are available to install, in your terminal window, run:

conda search python

This lists all packages whose names contain the text python.

To list only the packages whose full name is exactly python, add the --full-name option. In your terminal window, run:

conda search --full-name python

安装其他版本的 Python#

Installing a different version of Python

要在不覆盖当前版本的情况下安装其他版本的 Python,可创建一个新环境,并在其中安装目标 Python 版本:

  1. 创建新环境:

    • 要为 Python 3.9 创建新环境,请在终端窗口中运行:

      conda create -n py39 python=3.9
      

      备注

      py39 替换为你想创建的环境名称。python=3.9 表示你希望在该新环境中安装的包及其版本。也可以是任意其他软件包,例如 numpy=1.19,或 多个软件包

  2. 激活新环境

  3. 验证新环境是否为你的 当前环境

  4. 若要确认当前环境使用的是新版本的 Python,请在终端窗口中运行:

    python --version
    

To install a different version of Python without overwriting the current version, create a new environment and install the second Python version into it:

  1. Create the new environment:

    • To create the new environment for Python 3.9, in your terminal window run:

      conda create -n py39 python=3.9
      

      备注

      Replace py39 with the name of the environment you want to create. python=3.9 is the package and version you want to install in this new environment. This could be any package, such as numpy=1.19, or multiple packages.

  2. Activate the new environment.

  3. Verify that the new environment is your current environment.

  4. To verify that the current environment uses the new Python version, in your terminal window, run:

    python --version
    

安装 PyPy#

Installing PyPy

若要使用 PyPy 版本,可执行以下操作:

conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -n pypy pypy
conda activate pypy

To use the PyPy builds you can do the following:

conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -n pypy pypy
conda activate pypy

使用其他版本的 Python#

Using a different version of Python

若要切换到包含不同版本 Python 的环境,请 激活该环境

To switch to an environment that has different version of Python, activate the environment.

更新 Python#

Updating Python

若要将当前环境中的 Python 更新到最新版本,请运行:

conda update python

该命令会将 Python 更新至最新的主版本(例如从 python=3.10 升级到 python=3.12)。

若希望保持在某个次版本上,请改用 conda install 命令:

conda install python=3.10

To update Python to the latest version in your environment, run:

conda update python

This command will update you to the latest major release (e.g. from python=3.10 to python=3.12).

If you would like to remain on a minor release, use the conda install command instead:

conda install python=3.10