Python Object is Not Callable Error

When you mix up the class and module names, Python returns a TypeError:’module’ object that is not callable. While coding, this might happen for many reasons. To comprehend what “object is not callable” means, we must first comprehend what a Python callable is. As the title indicates, a callable object is something that could be called. Simply use the built-in method callable() and send it an object to see if it is callable.

Have you ever realized that while you’re running a Python code, the TypeError object isn’t accessible? We will work together to discover why this occurs. When an object that is not callable is called using parentheses (), the Python interpreter raises the “TypeError” i.e., the object is not a callable error. This can arise if you accidentally use parenthesis () rather than square brackets [] to retrieve elements of a list. We will show you some scenarios where this error occurs, as well as what you can do to fix it. Let’s look for the problem! But, what does it mean when an object isn’t callable?

When you call a module while coding, this might occur for many reasons. Most commons are when you call an object rather than a Class or Function within that module, you will get this error. Let’s have a look at each case and how to resolve “the’module’object” is not a callable problem.

Example 1:

In our first example, we will use a function to invoke a built-in Python module. The code below shows how to import a socket module in Python, and how to use it as a function afterward. Because we are using the similar name for the module and executing the “socket” module as a method, Python will raise the “TypeError:’module’ object is not callable”.

import socket

a = socket(socket.AF_INET, socket.SOCK_STREAM)


Here is the result screen that shows the generated error. It is most common among developers, who get confused between module names and class names.

Here are some solutions that can apply. The first solution is to call the function with **Modulename instead of calling the module name directly. Inside the module, there is a function named “FunctionName”.

import socket

a = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


Here is the result. As you can observe, the code was successfully executed and no errors were generated.

Altering the import statement as shown below, is another option. While executing the code, the compiler will not be confused between the module and function names.

As you can see, the code was successfully executed and no errors were generated.

from socket import *

a = socket(AF_INET, SOCK_STREAM)


Here, you can see the successful execution of the above code.

Example 2:

Another example is having a custom module named ” mymodule ” and utilizing it as a function, which results in a TypeError. We have built a file called “” in the example below.

def mymodule();

   n= ‘Python is easy to learn’


We try to import the mymodule and call it a function in the second step, which results in a TypeError.

import mymodule

print (mymodule())

Executing the above code generates an error as you can see in the attached screenshot.

Here is the best solution that you can apply when facing a similar situation. So, rather than importing the module, one can import the function or feature within the module, as shown below, to avoid the error.

from mymodule import mymodule

print (mymodule())

Here, you can see that after applying the above solution, the code is perfectly executed and displayed the following output.

Example 3:

To convert a value to a numerical value, use the int() function. The int() method returns an integer object made up of a number or a string x, or 0 if no parameters are provided. To be transformed into an integer object, a number or string must be provided. The value of the default parameter is zero.

int = 5

b = int(input('Enter value: '))

for i in range(1, int):

print(i * 5)

Below, you can see the result. As you can see, that it generates an error.

You can overcome this problem by giving the variable a different name. Refer to the below code.

a = 5

b = int(input('Enter value: '))

for i in range(1, a):

print(i * 5)

Here, the changes in the code produce the correct output as you can see below.


When a certain operation is performed on an object that has the wrong type, a TypeError is thrown. When you try to access a module as a function in your program, you’ll get a “TypeError:’module’ object is not callable” error. This arises when you get misled between the name of a module and the name of a class or method within that module. If you try to use the + operator to combine a string and an integer object, you’ll get a TypeError since the + operation isn’t allowed between objects of different types. In this post, we have shed light on the “TypeError: ‘Module’ Object Is Not Callable” and how to fix it in your Python programs.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content