【发布时间】:2019-05-27 20:18:37
【问题描述】:
我正在使用适用于 linux 的 windows 子系统(特别是适用于 Windows 的 Ubuntu)来运行一些 python 代码。当我尝试运行以下命令时:'import collections.abc',我收到以下错误:'ImportError: No module named abc'。
我可以导入'collections',但如果我尝试:'collections.abc',我会收到以下错误:'AttributeError:'module' object has no attribute 'abc''。
此外,我尝试在命令提示符下导入模块,而不使用 Ubuntu for Windows,并成功导入。
默认情况下,'collections' 模块应该包含在 python 中,所以我不确定它为什么会给我这个错误。
【问题讨论】:
-
您使用的是什么版本的 Python?
collections.abc在 3.3 版本中引入。命令提示符中的python -V是否返回与Ubuntu 子系统中的python -V相同的版本号? -
你也可以
import sys,然后print(sys.version_info)查看正在运行的Python版本。
标签: python windows-subsystem-for-linux