问题
I know this question has been asked before but there are very few solutions given and I don't understand the ones that are provided.
I'm trying to import my module packages and I receive the error below. The strange thing is this was all working 2 days ago and I haven't really done anything since with it so I can't understand why this is now appearing.
import plotly.offline as pyo
from plotly.graph_objs import *
from plotly import tools
import plotly.plotly as py
import pandas as pd
import math as m
pyo.offline.init_notebook_mode()
this returns the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-f7b4615963aa> in <module>()
----> 1 import plotly.offline as pyo
2 from plotly.graph_objs import *
3 from plotly import tools
4 import plotly.plotly as py
5 import pandas as pd
C:\Users\Lewis\Anaconda3\Lib\site-packages\plotly\plotly\__init__.py in <module>()
8
9 """
---> 10 from . plotly import (
11 sign_in,
12 update_plot_options,
C:\Users\Lewis\Anaconda3\Lib\site-packages\plotly\plotly\plotly.py in <module>()
28 from requests.compat import json as _json
29
---> 30 from plotly import exceptions, files, session, tools, utils
31 from plotly.api import v1, v2
32 from plotly.plotly import chunked_requests
ImportError: cannot import name 'exceptions'
I've tried updating Plotly but this didn't do anything either. Could this be because I installed Jupyter notebook with my Anaconda installation, and my Lib\site-packages directory is within the Anaconda3 dir? Can't imagine this would be the cause but I can't think of much else. Any ideas?
[edit]
import sys
sys.path
['',
'C:\\Users\\Lewis\\Anaconda3\\Lib\\site-packages\\plotly',
'C:\\Users\\Lewis\\Anaconda3\\python36.zip',
'C:\\Users\\Lewis\\Anaconda3\\DLLs',
'C:\\Users\\Lewis\\Anaconda3\\lib',
'C:\\Users\\Lewis\\Anaconda3',
'C:\\Users\\Lewis\\Anaconda3\\lib\\site-packages',
'C:\\Users\\Lewis\\Anaconda3\\lib\\site-packages\\Sphinx-1.5.6-py3.6.egg',
'C:\\Users\\Lewis\\Anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\Lewis\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\Lewis\\Anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\Lewis\\Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg',
'C:\\Users\\Lewis\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\Lewis\\.ipython']
回答1:
in my case, after doing the upgrade like @Max above suggested, restarting the kernel finally fixed the problem
回答2:
pip install --upgrade plotly
run the above command. it will work
来源:https://stackoverflow.com/questions/46296982/plotly-cannot-import-name-exceptions