如何使用 conda 更新到最新的 Python 版本?

问题描述 投票:0回答:4

我是Python新手。我被要求使用

conda
更新到最新的 Python 版本。

到目前为止,我已经在我的 Mac 上安装了 Anaconda。所以我主要使用终端。

提前谢谢您。

python conda
4个回答
36
投票

没有虚拟环境或环境内部,可以按如下方式更新python:

conda update python

或者可以升级或降级环境python版本:

conda install python=3.7

更新或升级Python


23
投票

打开 conda shell 提示符。 (在 Windows Anaconda Powershell 提示符上)

你先检查一下

conda search python

您将获得所有支持的版本。它可能看起来像:

Loading channels: done
# Name                       Version           Build  Channel
python                        2.7.13     h1b6d89f_16  pkgs/main
python                        2.7.13     h9912b81_15  pkgs/main
python                        2.7.13     hb034564_12  pkgs/main
python                        2.7.14     h2765ee6_18  pkgs/main
python                        2.7.14     h3e68818_15  pkgs/main
python                        2.7.14     h4084c39_22  pkgs/main
python                        2.7.14     h4a10d90_30  pkgs/main
python                        2.7.14     h4a10d90_31  pkgs/main
python                        2.7.14     h59f5a59_20  pkgs/main
python                        2.7.14     h819644d_16  pkgs/main
python                        2.7.14     h8c3f1cb_23  pkgs/main
python                        2.7.15      h2880e7c_2  pkgs/main
python                        2.7.15      h2880e7c_3  pkgs/main
python                        2.7.15      h2880e7c_4  pkgs/main
python                        2.7.15     hcb6e200_15  pkgs/main
python                        2.7.15      hcb6e200_5  pkgs/main
python                        2.7.15      hcb6e200_7  pkgs/main
python                        2.7.15      he216670_0  pkgs/main
python                        2.7.16      hcb6e200_0  pkgs/main
python                        2.7.17      h930f6bb_0  pkgs/main
python                         3.5.4     h1357f44_23  pkgs/main
python                         3.5.4     hc495aa9_21  pkgs/main
python                         3.5.4     hd3c4935_11  pkgs/main
python                         3.5.4     hdec4e59_20  pkgs/main
python                         3.5.4     hedc2606_15  pkgs/main
python                         3.5.5      h0c2934d_0  pkgs/main
python                         3.5.5      h0c2934d_1  pkgs/main
python                         3.5.5      h0c2934d_2  pkgs/main
python                         3.5.6      he025d50_0  pkgs/main
python                         3.6.2     h09676a0_15  pkgs/main
python                         3.6.2     h6679aeb_11  pkgs/main
python                         3.6.3      h210ce5f_2  pkgs/main
python                         3.6.3      h3389d20_0  pkgs/main
python                         3.6.3      h3b118a2_4  pkgs/main
python                         3.6.3      h9e2ca53_1  pkgs/main
python                         3.6.4      h0c2934d_2  pkgs/main
python                         3.6.4      h0c2934d_3  pkgs/main
python                         3.6.4      h6538335_0  pkgs/main
python                         3.6.4      h6538335_1  pkgs/main
python                         3.6.5      h0c2934d_0  pkgs/main
python                         3.6.6      hea74fb7_0  pkgs/main
python                         3.6.7      h33f27b4_0  pkgs/main
python                         3.6.7      h33f27b4_1  pkgs/main
python                         3.6.7      h9f7ef89_2  pkgs/main
python                         3.6.8      h9f7ef89_0  pkgs/main
python                         3.6.8      h9f7ef89_1  pkgs/main
python                         3.6.8      h9f7ef89_7  pkgs/main
python                         3.6.9      h5500b2f_0  pkgs/main
python                         3.7.0      hea74fb7_0  pkgs/main
python                         3.7.1      h33f27b4_3  pkgs/main
python                         3.7.1      h33f27b4_4  pkgs/main
python                         3.7.1      h8c8aaf0_6  pkgs/main
python                         3.7.1      he44a216_5  pkgs/main
python                         3.7.2      h8c8aaf0_0  pkgs/main
python                         3.7.2     h8c8aaf0_10  pkgs/main
python                         3.7.2      h8c8aaf0_2  pkgs/main
python                         3.7.3      h8c8aaf0_0  pkgs/main
python                         3.7.3      h8c8aaf0_1  pkgs/main
python                         3.7.4      h5263a28_0  pkgs/main
python                         3.7.5      h8c8aaf0_0  pkgs/main
python                         3.8.0      hff0d562_0  pkgs/main
python                         3.8.0      hff0d562_1  pkgs/main
python                         3.8.0      hff0d562_2  pkgs/main

然后简单选择版本

conda install python=3.8.0
(如果这是最后一个版本)。


0
投票

我相信您的要求是使用最新的Python版本创建一个虚拟环境。您可以通过执行命令来完成:

conda create -n my_env python=3.7

这里

my_env
只是环境的名称,因此您可以将其替换为任何内容。另外,Python 3.7 是截至撰写本文时的最新 Python 版本,但将来可能需要随更高版本进行更改。

创建环境后,您可以通过输入

source activate my_env
来激活它(正如有用的 conda 消息将指出的那样)。


0
投票

您下载 anaconda 可执行文件时,您的 conda 基础环境具有最新版本的 python。

意思是,如果你想升级你的基础 anaconda python,比如从 Python 3.7 到 Python 3.10,你有两个选择:

  1. 卸载当前版本并安装最新版本 蟒蛇。
  2. 创建一个python版本高于conda基础环境python版本的环境

为什么?

例如,如果您的 anaconda 基础环境有 python 3.7,则您可以获得的最大 python 是 3.7.13.final,如沙盒环境下面的日志输出所示。

在终端中运行:

conda activate base

在终端中运行(使用 python 3.7 的 conda 环境大约支持最大):

conda install -n base conda=23.1.0

在终端中运行:

conda info

输出:

     active environment : base
    active env location : xxxxxxxxxxxxxxxxxx
            shell level : 1
       user config file : xxxxxxxxxxxxxxxxxx
 populated config files : xxxxxxxxxxxxxxxxxx
          conda version : 23.1.0
    conda-build version : 3.23.3
         python version : 3.7.13.final.0
       virtual packages : xxxxxxxxxxxxxxxxxx
                          xxxxxxxxxxxxxxxxxx
       base environment : xxxxxxxxxxxxxxxxxx
      conda av data dir : xxxxxxxxxxxxxxxxxx
  conda av metadata url : None
           channel URLs : xxxxxxxxxxxxxxxxxx
          package cache : xxxxxxxxxxxxxxxxxx
       envs directories : xxxxxxxxxxxxxxxxxx
               platform : xxxxxxxxxxxxxxxxxx
             user-agent : conda/23.1.0 requests/2.28.1 CPython/3.7.13
          administrator : False
             netrc file : None
           offline mode : False

如果您尝试安装更高的 conda 版本怎么办?

例如,如果您尝试安装 conda 版本,认为它也会升级您的 python 版本,您将收到如下错误(请注意发布此答案的日期;错误消息可能会随着 anaconda 软件的发展而变化) ).

在终端中运行:

conda install -n base conda=23.7.4

输出:

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: |
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort./
failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - conda=23.7.4 -> python[version='>=3.10,<3.11.0a0|>=3.11,<3.12.0a0|>=3.8,<3.9.0a0|>=3.9,<3.10.0a0']

Your python: python=3.7

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
© www.soinside.com 2019 - 2024. All rights reserved.