Victor Guijarro
Victor Guijarro

Reputation: 53

TypeError: 'module' object is not callable from Jupyter notebook

I am trying to use a module located in the same directory as the script I am running and I get the following error:

TypeError: 'module' object is not callable

This was working before, but I did some modifications to the sys.path list since I wanted to call modules from other directories, and from that point it stopped working.

This is my folder's structure:

Neural_Network/
  split_data.py
  test.ipynb

I get the error executing test.ipynb:

import split_data
import os

print(split_data.__file__)
trainset, testset, valset = split_data.split_data_func(os.path('data'))

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_4936/633432209.py in <module>
      4 
      5 print(split_data.__file__)
----> 6 trainset, testset, valset = split_data.split_data_func(os.path('data'))
      7 
      8 """"

TypeError: 'module' object is not callable

print(split_data.__file__) is giving the right path to the module.

The module split_data.py has a single function:

import math
import os
import random
def split_data_func(path):
...
  return trainset, testset, valset

This was working before and I don't know what could have happened.

In the sys.path I have the path to Neural_Network/ directory.

UPDATE

I was looking the error regarding the split_data module and the error was with the os module, I just changed to:

trainset, testset, valset = split_data.split_data_func(os.path.join(os.getcwd(),'dataset_days'))

Upvotes: 0

Views: 6060

Answers (1)

pletnes
pletnes

Reputation: 479

os.path is a module which contains functions. Since it's a module, you can't use it as a function. Did you mean pathlib.Path instead of os.path? Or did you mean to call one of the functions within, like os.path.join('data', split_data.__file__)?

The error is unrelated to the code being run in a notebook, it's a common python error.

Upvotes: 1

Related Questions