Module object is not callable

I was trying to use plotly to plot a ohlc chart. However, it kept saying that the module object is not callable. However, with the same codes, the author was able to do it in the tutorial i followed.
Thank you!

import pandas as pd

import plotly.plotly as py
import plotly.graph_objs as go

df = pd.read_csv(“USDCAD_hour.csv”)

df.columns = [‘date’,‘open’,‘high’,‘low’,‘close’,‘volume’]

df.date = pd.to_datetime(df.date,format="%d.%m.%Y %H:%M:%S.%f")

df = df.set_index(df.date)

df =df[[‘open’,‘high’,‘low’,‘close’,‘volume’]]

df = df.drop_duplicates(keep=False)

#print(df.head(11))

trace = go.ohlc(x=df.index,open=df.open, high=df.high,low=df.low,close=df.close, name=‘usdcad’)

data=[trace]

py.plot(data,filename=‘usdcad.html’)

Hi @yanzifan,

Could you put your code in a fenced code block (https://help.github.com/articles/creating-and-highlighting-code-blocks/) and include the full error message and stack trace (This usually indicates which line caused the exception).

Thanks!
-Jon

Hi, Jmmease. thank you for your reply. I found out why i got the error. it is because my case was wrong (ohlc should be Ohlc)

1 Like

This error statement TypeError: ‘module’ object is not callable is raised as you are being confused about the Class name and Module name. The problem is in the import line . You are importing a module, not a class. This happend because the module name and class name have the same name .

If you have a class “MyClass” in a file called “MyClass.py” , then you should import :

from MyClass import MyClass

In Python , a script is a module, whose name is determined by the filename . So when you start out your file MyClass.py with import MyClass you are creating a loop in the module structure.

-- coding: utf-8 --

“”"
Editor de Spyder

@author: jackson
“”"
from sympy import symbol
from sympy import integrate
from scipy.integrate import quad

x=symbol(‘x’)
print (integrate(x3+x2+1, x))
f=lambda x:x3+x2+1
print(quad(f,1,2))