AttributeError: 'module' 对象没有属性 'scandir'

Aid*_*ido 3 python scandir python-3.x python-os

我不知道为什么会这样。这是函数:

def scanWallDir(basedir, scansubdirs=True):
    wallsOut = []
    for entry in os.scandir(basedir):
        if entry.is_file():
            print(("file " + entry.name))
        elif entry.is_dir():
            print(("dir  " + entry.name))
Run Code Online (Sandbox Code Playgroud)

和错误:

/usr/bin/python2.7 /home/aidan/Code/ulwscs/ulwscs.py
Traceback (most recent call last):
  File "/home/aidan/Code/ulwscs/ulwscs.py", line 38, in <module>
    scanWallDir("/media/Crossover/Wallpapers")
  File "/home/aidan/Code/ulwscs/ulwscs.py", line 11, in scanWallDir
    for entry in os.scandir(basedir):
AttributeError: 'module' object has no attribute 'scandir'

Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

有谁知道会发生什么?

Aid*_*ido 5

Pycharm 重置了我使用的 Python 版本。我是个白痴。