0
votes

import matplotlib and %matplotlib inline are not working. Getting the following errors.

On the anaconda prompt I ran this command as well.

conda install matplotlib

Even after this, this did not work.

Just observed a strange thing.

When I launched using the command jupyter lab from the anaconda prompt, microsoft edge browser launched. And in that this works fine. But when I opened in chrome browser, this gives the problem.

enter image description here

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-0484cd13f94d> in <module>()
----> 1 import matplotlib

ModuleNotFoundError: No module named 'matplotlib'


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-9e3324102725> in <module>()
----> 1 get_ipython().run_line_magic('matplotlib', 'inline')

~\AppData\Local\conda\conda\envs\scipy18jlab\lib\site- 
packages\IPython\core\interactiveshell.py in run_line_magic(self,     
magic_name, line, _stack_depth)
   2129                 kwargs['local_ns'] = 
sys._getframe(stack_depth).f_locals
   2130             with self.builtin_trap:
-> 2131                 result = fn(*args,**kwargs)
   2132             return result
   2133 

<decorator-gen-108> in matplotlib(self, line)

~\AppData\Local\conda\conda\envs\scipy18jlab\lib\site- 

packages\IPython\core\magic.py in (f, *a, **k) 185 # but it's overkill for just that one bit of state. 186 def magic_deco(arg): --> 187 call = lambda f, *a, **k: f(*a, **k) 188 189 if callable(arg):

~\AppData\Local\conda\conda\envs\scipy18jlab\lib\site- 

packages\IPython\core\magics\pylab.py in matplotlib(self, line) 97 print("Available matplotlib backends: %s" % backends_list) 98 else: ---> 99 gui, backend = self.shell.enable_matplotlib(args.gui) 100 self._show_matplotlib_backend(args.gui, backend) 101

    ~\AppData\Local\conda\conda\envs\scipy18jlab\lib\site- 
   packages\IPython\core\interactiveshell.py in enable_matplotlib(self, gui)
       3035         """
       3036         from IPython.core import pylabtools as pt
    -> 3037         gui, backend = pt.find_gui_and_backend(gui, 
    self.pylab_gui_select)
       3038 
       3039         if gui != 'inline':

    ~\AppData\Local\conda\conda\envs\scipy18jlab\lib\site- 
   packages\IPython\core\pylabtools.py in find_gui_and_backend(gui, 
gui_select)
        271     """
        272 
    --> 273     import matplotlib
        274 
        275     if gui and gui != 'auto':

    ModuleNotFoundError: No module named 'matplotlib'
2

2 Answers

0
votes

I am not sure why, pasting the entire url generated from the anaconda prompt worked.

So I did the following.

  1. installed the matplotlib using the command conda install matplotlib
  2. Then typed the command jupyter lab.
  3. Then pasted the entire url shown as follows in the chrome browser. Then it working.

enter image description here

0
votes

Indeed, in the conda documentation - browser compatibility section, you can read:

The Jupyter Notebook aims to support the latest versions of these browsers:
Chrome
Safari
Firefox
Up to date versions of Opera and Edge may also work, but if they don’t, please use one of the supported browsers. Using Safari with HTTPS and an untrusted certificate is known to not work (websockets will fail).

You might consider to set up one of the compatible browsers as your default to avoid having to copy/paste the url every time.