Reputation: 3744
When searching about this issue, I came across some questions asking the opposite, i.e., package opens in iPython but not in Jupyter Notebook. But in my case, its the opposite. That's why I posted this question.
I added path\to\anaconda3
and path\to\anaconda3\Lib\site-packages
in the environment variable, but it doesn't solve the issue.
I can see the packages in the site-packages
folder:
But I just can't import some of the packages in iPython:
or with python in the anaconda cmd:
But it works fine in Jupyter Notebook:
What do/can I do to fix this?
Here's some more info if it helps:
(base) C:\Users\h473>where python
C:\Users\h473\AppData\Local\Continuum\anaconda3\python.exe
(base) C:\Users\h473>where conda
C:\Users\h473\AppData\Local\Continuum\anaconda3\Library\bin\conda.bat
C:\Users\h473\AppData\Local\Continuum\anaconda3\Scripts\conda.exe
(base) C:\Users\h473>where pip
C:\Users\h473\AppData\Local\Continuum\anaconda3\Scripts\pip.exe
P.S.: It doesn't happen for all packages, only some packages, as shown for pandas, numpy and matplotlib in the screenshot below.
Upvotes: 2
Views: 1097
Reputation: 20472
When you are using matplotlib
(and seaborn
is built on top of it) it needs to use a so called backend that is used to display the actual GUI with the plot in it once you execute for example matplotlib.pyplot.show()
.
When you are running a Jupyter Notebook with matplotlib in inline mode (default I think, but not sure), then a Jupyter specific backend is used (module://ipykernel.pylab.backend_inline
). That makes sense, since the plots should not appear in separate windows, but be displayed inside the notebook itself.
When you are in an interactive python or iPython session however, Qt5 was used as
import matplotlib
print(matplotlib.rcParams["backend"]) # this prints the backend that would be loaded when trying anything with pyplot
has revealed. Since you get the error youa re getting, it looks like your QT5 installation is broken. You can try to reinstall them using the conda commands, but for now you could also fall back to using a different backend, that you need to specify before trying to load seaborn:
import matplotlib
matplotlib.use("TkAgg") #use backend TkAgg
import seaborn
You can also change the default backend being loaded to TkAgg by creating a matplotlibrc
file in C:\Users\<your name>\.matplotlib\
with
backend : TkAgg
in it.
Upvotes: 2