Python Forum
AttributeError: module 'plotly' has no attribute 'offline'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: module 'plotly' has no attribute 'offline'
#1
Hi

im a complete beginner and would greatly appreciate if you guys could help me on the below code from a tutorial. Im using Pycharm community edition.


import pandas as pd
import plotly as py
from plotly import tools
#import plotly.offline as offline
import plotly.graph_objs as go


#from plotly import tools
#import plotly.graph_objs as go

df = pd.read_csv("EURUSDhours.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)

trace = go.Ohlc(x=df.index,open=df.open,high=df.high,low=df.low,close=df.close,name='Currency Quote')
data = [trace]

py.offline.plot(data,filename='tutorial.html')



Error message : "AttributeError: module 'plotly' has no attribute 'offline'"
Reply
#2
Your line #import plotly.offline as offline is commented (line starts with # symbol means it is a comment). PyCharm also colours comments differently than rest of code, so you can spot it easily.
Next time when posting code, please put code in Python code tags. And full error traceback in error code tags.
Reply
#3
(Jan-19-2018, 07:18 PM)j.crater Wrote: Your line #import plotly.offline as offline is commented (line starts with # symbol means it is a comment). PyCharm also colours comments differently than rest of code, so you can spot it easily.
Next time when posting code, please put code in Python code tags. And full error traceback in error code tags.

OK noted. I'm aware that #import plotly.offline as offline is commented. I was trying out solutions posted online. But it didnt work for me.

import pandas as pd
import plotly as py
from plotly import tools
import plotly.graph_objs as go

df = pd.read_csv("EURUSDhours.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)

trace = go.Ohlc(x=df.index,open=df.open,high=df.high,low=df.low,close=df.close,name='Currency Quote')
data = [trace]

py.offline.plot(data,filename='tutorial.html')
C:\Users\czc19\PycharmProjects\untitled1\venv\Scripts\python.exe C:/Users/czc19/Desktop/html.py
Traceback (most recent call last):
  File "C:/Users/czc19/Desktop/html.py", line 2, in <module>
    import plotly as py
  File "C:\Users\czc19\PycharmProjects\untitled1\venv\lib\site-packages\plotly\__init__.py", line 31, in <module>
    from plotly import (plotly, dashboard_objs, graph_objs, grid_objs, tools,
  File "C:\Users\czc19\PycharmProjects\untitled1\venv\lib\site-packages\plotly\plotly\__init__.py", line 10, in <module>
    from . plotly import (
  File "C:\Users\czc19\PycharmProjects\untitled1\venv\lib\site-packages\plotly\plotly\plotly.py", line 28, in <module>
    from requests.compat import json as _json
  File "C:\Users\czc19\PycharmProjects\untitled1\venv\lib\site-packages\requests\__init__.py", line 97, in <module>
    from . import utils
  File "C:\Users\czc19\PycharmProjects\untitled1\venv\lib\site-packages\requests\utils.py", line 11, in <module>
    import cgi
  File "C:\Users\czc19\AppData\Local\Programs\Python\Python36-32\Lib\cgi.py", line 42, in <module>
    import html
  File "C:\Users\czc19\Desktop\html.py", line 17, in <module>
    py.offline.plot(data,filename='tutorial.html')
AttributeError: module 'plotly' has no attribute 'offline'

Process finished with exit code 1
Reply
#4
Hmmm I see... Well I found this website. It says Plotly version should be at least 1.9.4 to use offline plotting. So do something like this to check the version (you can use Python interpreter for this simple check):

import plotly
plotly.__version__
Reply
#5
(Jan-20-2018, 09:30 AM)j.crater Wrote: Hmmm I see... Well I found this website. It says Plotly version should be at least 1.9.4 to use offline plotting. So do something like this to check the version (you can use Python interpreter for this simple check):

import plotly
plotly.__version__

im using the latest version 2.2.3 :(

Is there anything wrong with my python code?

Thank you.
Reply
#6
Your Python code looks fine. Can you post the CSV file, or at least copy out first say 10 lines, that will enable me to try the code myself?
Reply
#7
Nevermind, I made up some data and code runs fine for me, makes an html file and opens plot in browser. I used the code you posted in your second post.
First thing which comes to mind is to reinstall plotly, making sure you are doing it in the right Python installation or virtual environment, if you are using one.
Reply
#8
(Jan-20-2018, 05:13 PM)j.crater Wrote: Nevermind, I made up some data and code runs fine for me, makes an html file and opens plot in browser. I used the code you posted in your second post.
First thing which comes to mind is to reinstall plotly, making sure you are doing it in the right Python installation or virtual environment, if you are using one.

hmmm thanks for your help. I think it has to do with naming the file as html.py Dodgy

It works when i deleted that file and created a new one with the same code.
Reply
#9
yes, you are right, it was issue with the name. you were shadowing html module from the standard library which is used - see lines #15-16 in your traceback. it actually imports your own script and from there things get messed...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  installing anaconda packages offline HulkHogansArmsArePythons 4 1,016 Feb-18-2020, 08:23 PM
Last Post: jefsummers
  AttributeError: (“module 'pandas' has no attribute 'rolling_std'” Mariana136 4 2,624 Sep-23-2019, 12:56 PM
Last Post: Mariana136
  AttributeError: module 'numpy' has no attribute 'array aapurdel 7 17,890 May-29-2019, 02:48 AM
Last Post: heiner55
  Pandas to_csv in for loop AttributeError: 'tuple' object has no attribute 'to_csv' NSearch 9 6,570 Apr-22-2019, 05:05 PM
Last Post: Yoriz
  Tensorflow offline build from source on CentOS 7 riotto 3 1,589 Mar-21-2019, 07:16 PM
Last Post: riotto
  AttributeError: 'NoneType' object has no attribute 'all' synthex 2 1,827 Mar-07-2019, 11:11 AM
Last Post: synthex
  Please help with AttributeError: 'Netz' object has no attribute 'conv' DerBerliner 2 1,265 Feb-27-2019, 06:01 PM
Last Post: DerBerliner
  AttributeError: Can't get attribute 'Individual' on <module 'deap.creator' DomClout 4 3,639 Jul-27-2018, 09:05 PM
Last Post: Vysero
  AttributeError: module 'mnist' has no attribute 'train_images' pythonbeginner 1 3,825 Jun-14-2018, 09:29 PM
Last Post: snippsat
  AttributeError: 'set' object has no attribute 'items hey_arnold 3 15,986 Apr-29-2018, 04:33 PM
Last Post: hey_arnold

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020