You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Colab切换Python版本后pip失效及语法报错问题求助

在Google Colab中切换Python版本遇到的问题

当前Google Colab环境默认运行Python 3.7:

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

为切换到Python 3.10,执行了以下命令:

! 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 install gym或!pip3 install gym均报错:

AttributeError: module 'collections' has no attribute 'MutableMapping'

2. 版本显示与实际运行版本不一致

虽然版本查询结果为3.10,但实际仍在运行Python 3.7,使用Python 3.8及以上版本的新语法时出现报错:

[In]: (a := 3)
[Out]: SyntaxError: invalid syntax
[In]: a: list[int] = [1]
[Out]: TypeError: 'type' object is not subscriptable

内容的提问来源于stack exchange,提问作者AAriam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 05:36:17