close

[Solved] TypeError: ‘module’ object is not callable

Hello Guys, How are you all? Hope You all Are Fine. When I run my code getting this error TypeError: ‘module’ object is not callable in Python. So Here I am Explain to you all the possible solutions here.

Without Wasting your time, Lets start This Article to Solve This Error.

How TypeError: ‘module’ object is not callable Error Occurs ?

When I run my code getting this error:

File "C:\Users\ssc\Pyhon_project\demo\myapp.py", line 82, in __init__
    self.serv = socket(AF_INET,SOCK_STREAM)
TypeError: 'module' object is not callable

How To Solve TypeError: ‘module’ object is not callable error ?

Question: How To Solve TypeError: ‘module’ object is not callable error?
Answer: To Solve TypeError: ‘module’ object is a not callable error “module object is not callable. Python is telling me my code trying to call something that cannot be called. What is my code trying to call? so that you have to import where you got an error.

Solution 1

You are calling a file/directory as a function instead of real function that is your problem. suppose we have two file main.py and fun1.py

My fun1.py

#inside fun1.py
def fun1():
  pass

My main.py

#inside main.py file
import fun1
fun1() #here create refers to fun1.py , so fun1.fun1() would work here

It gives this error as am calling the create.py file as a function. so I gotta do this:

from fun1 import fun1
fun1() #now it works.

Solution 2

module object is not callable. Python is telling me my code trying to call something that cannot be called. What is my code trying to call? so that you have to import where you got error.

Solution 3

Assume that the content of MyClass.py is:

class MyClass:
    # ......

If you use:

from MyClass import MyClass# means MyClass.py

In this way, you will get TypeError: ‘module’ object is not callable if you then tried to call MyClass().

But, if you use:

from MyClass.MyClass import MyClass# means Class YourClass

or use MyClass.MyClass(), it works.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment