AttributeError: Module Has No Attribute

AttributeError: module 'os' has no attribute 'listdirs'

Quick Answer

You are accessing a name that does not exist on the module. This is usually a typo or using the wrong module. Check the module docs for the correct name.

Why This Happens

When you access module.attribute, Python looks up the name in the module namespace. If it does not exist, you get AttributeError. Common causes include typos, outdated APIs, or a local file shadowing the standard library module.

The Problem

import os
files = os.listdirs('.')

The Fix

import os
files = os.listdir('.')

Step-by-Step Fix

  1. 1

    Check for typos

    Compare your attribute name against the documentation. Use dir(module) to list attributes.

  2. 2

    Check for file shadowing

    Make sure you do not have a local file named the same as the module (e.g., os.py).

  3. 3

    Verify module version

    Some attributes are only available in newer versions.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free