Search code examples
pythonpython-3.xscandirpython-os

AttributeError: 'module' object has no attribute 'scandir'


I have no idea why this is happening. Here's the function:

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))

And the error:

/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

Does anyone know what could be heppening?


Solution

  • Pycharm reset which version of Python I was using. I'm an idiot.