管理 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 版本:
To install a different version of Python without overwriting the current version, create a new environment and install the second Python version into it:
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 asnumpy=1.19
, or multiple packages.
Verify that the new environment is your current environment.
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