[Python] ModuleNotFoundError: No module named 'Teacher' in Python when importing from another...

Discussão em 'Python' iniciado por Stack, Abril 4, 2025.

  1. Stack

    Stack Membro Participativo

    ModuleNotFoundError: No module named 'Teacher' even though the file exists


    I am trying to import a function from one Python file to another, but I keep getting the error:

    ModuleNotFoundError: No module named 'Teacher'


    Here’s my project structure:

    D:\Devang\PYTHON PW SKILLS
    ├── Student
    ├── student_details.py
    ├── Teacher
    ├── teacher_details.py

    teacher_details.py (inside the Teacher folder):


    def teacher():
    print("This is a teacher function")

    student_details.py (inside the Student folder):((


    from Teacher import teacher_details

    class Student:
    print("This is a student class")

    teacher_details.teacher()


    Steps I tried:

    I ran python student_details.py from the Student folder.

    I tried adding sys.path.append('..') to manually set the path.

    I verified that teacher_details.py exists inside Teacher/.

    But I still get:

    ModuleNotFoundError: No module named 'Teacher'


    How do I fix this? Am I missing something in my import statement?

    Continue reading...

Compartilhe esta Página