ModuleNotFoundError: No module named 'A given module in package' when running the code


Here is the entire code:

     * mypkg/

I am trying to run this app from :

class Person:
    def __init__(self,name,age,address): = name
        self.age = age
        self.address = address

    def show_person(self):
        return "the name of the person is {0} and age is {1} ".format(,self.age) :

import mod1 as P

class Student(P.Person):
    def __init__(self,name,age,address,standard,grade):
        self.standard = standard
        self.grade = grade

    def show_student(self):
        return "The name of the student is {0} and he is studing in {1} standard".format(,self.standard)

__all__ = ["mod1","mod2"] :

from mypkg import *

a = Person('John',12,'Near S School')

b = Student('name', 17, 'Near X Resturant',12, 'B')

The output:

Traceback (most recent call last):
  File "", line 1, in <module>
    from mypkg import *
  File "", line 1, in <module>
    import mod1 as P
ModuleNotFoundError: No module named 'mod1'

The output should be a string with name and standard

Example :

The name of the Student is Jhon and he is studying in standard 10.

Asked By: Satyaki De Sarkar



In, change the import to

import mypkg.mod1 as P

In, change the import to

from mypkg.mod1 import Person
from mypkg.mod2 import Student

This should allow you to run the program.

Answered By: Fractalism
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.