Tag Archives: TypeError: ‘module’ object is not callable

TypeError: ‘module’ object is not callable

Knowledge map advanced must read: read how large-scale map data efficient storage and retrieval>>>

[toc]

Problem description

Run command

Error log

Traceback (most recent call last):
  File "./run.py", line 125, in <module>
    model = get_unet()
  File "./run.py", line 103, in get_unet
    up6 = merge([UpSampling2D(size=(2, 2))(conv5), conv4], mode='concat', concat_axis=1)
TypeError: 'module' object is not callable

Solutions

Install historical versions of keras before 2.1.6[ Releases ]

# pip install https://github.com/keras-team/keras/releases/tag/2.1.6

Problem analysis

1. According to the error log, the module was not found. 2. Check (under the search path) whether there is no such module

>>> import sys
>>> print(sys.path)

3. See if there is a merge.py module (file) in the installation path of keras

$ pip install keras

4. Keras has been installed and from keras.layers import merge has been introduced in the header file. But why not

5. The merge module (file) does exist

6. Open merge.py and find that there is no merge() function, so it will not be called[ Ref]

How to Solve Python TypeError: ‘module’ object is not callable

When I am used to writing java code, I will try to define package when I write Python code. However, when I introduce it, I report an error: typeerror: ‘module’ object is not called

Why

For example, I create the person. Py source file in the package, and then create the student class in this file

How to import the student class

Habitual thinking, from clazz. Student is OK, but it is not

The correct way is from clazz.person import student or from clazz.person import*

That is to say, which classes are imported from which py file under which package