【问题标题】:Google Colab Python version not changingGoogle Colab Python 版本没有改变
【发布时间】:2022-11-23 18:23:03
【问题描述】:

我想更改我的 Google Colab 上的 python 版本。 目前,它正在运行 python 3.7:

[In]: ! python --version
[Out]: Python 3.7.13

我想要 python 3.10,所以我按照this post中的说明进行操作:

! sudo apt-get update -y
! sudo apt-get install python3.10
! sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
! sudo update-alternatives --config python3

这里打印了一个列表,我选择python 3.10。然后

! sudo apt install python3-pip

现在,当我查询 python 版本时,它显示 3.10:

[In]: ! python --version
[Out]: Python 3.10.6

到目前为止,一切都很好!,现在有两个问题:

  1. pip 似乎完全坏了;我无法 pip 安装任何东西,例如!pip install gym!pip3 install gym 都出现以下错误:
    AttributeError: module 'collections' has no attribute 'MutableMapping'
    
    1. Python 版本显示 3.10,但似乎还是 3.7,因为较新的语法会引发语法错误,例如:
    [In]: (a := 3)
    [Out]: SyntaxError: invalid syntax
    
    [In]: a: list[int] = [1]
    [Out]: TypeError: 'type' object is not subscriptable
    

【问题讨论】:

标签: python google-colaboratory


【解决方案1】:

你必须降级 python。

自 3.3 版后弃用,将在 3.10 版中删除:已移动 Collections 抽象基类到 collections.abc 模块。为了 向后兼容,它们在此模块中继续可见 通过 Python 3.9。

参考https://docs.python.org/3.9/library/collections.html

【讨论】:

  • 你是什​​么意思?我想从 3.7 升级到 3.10!
  • 3.10 版本无法调用 collections.MutableMapping。它已更改为 collections.abc.MutableMapping。有几种方法可以解决这个问题,但在 colab 上似乎很难。
【解决方案2】:

不能评论网站有问题但我有同样的问题

【讨论】:

猜你喜欢
  • 2021-10-24
  • 1970-01-01
  • 2019-01-29
  • 1970-01-01
  • 2019-05-17
  • 2020-11-19
  • 2023-03-04
  • 2019-07-25
  • 1970-01-01
相关资源
最近更新 更多