![]() |
AttributeError: module 'plotly' has no attribute 'offline' - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: AttributeError: module 'plotly' has no attribute 'offline' (/thread-7659.html) |
AttributeError: module 'plotly' has no attribute 'offline' - charlesczc - Jan-19-2018 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'" RE: AttributeError: module 'plotly' has no attribute 'offline' - j.crater - Jan-19-2018 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. RE: AttributeError: module 'plotly' has no attribute 'offline' - charlesczc - Jan-20-2018 (Jan-19-2018, 07:18 PM)j.crater Wrote: Your line 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 RE: AttributeError: module 'plotly' has no attribute 'offline' - j.crater - Jan-20-2018 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__ RE: AttributeError: module 'plotly' has no attribute 'offline' - charlesczc - Jan-20-2018 (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): im using the latest version 2.2.3 :( Is there anything wrong with my python code? Thank you. RE: AttributeError: module 'plotly' has no attribute 'offline' - j.crater - Jan-20-2018 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? RE: AttributeError: module 'plotly' has no attribute 'offline' - j.crater - Jan-20-2018 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. RE: AttributeError: module 'plotly' has no attribute 'offline' - charlesczc - Jan-20-2018 (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. hmmm thanks for your help. I think it has to do with naming the file as html.py ![]() It works when i deleted that file and created a new one with the same code. RE: AttributeError: module 'plotly' has no attribute 'offline' - buran - Jan-21-2018 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... |