%matplotlib notebook
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-7a6b33cdc204> in <module>
----> 1 get_ipython().run_line_magic('matplotlib', 'notebook')
c:\users\diede\appdata\local\programs\python\python39\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2325 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2326 with self.builtin_trap:
-> 2327 result = fn(*args, **kwargs)
2328 return result
<decorator-gen-102> in matplotlib(self, line)
c:\users\diede\appdata\local\programs\python\python39\lib\site-packages\IPython\core\magic.py in <lambda>(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)
189 if callable(arg):
c:\users\diede\appdata\local\programs\python\python39\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.lower() if isinstance(args.gui, str) else args.gui)
100 self._show_matplotlib_backend(args.gui, backend)
c:\users\diede\appdata\local\programs\python\python39\lib\site-packages\IPython\core\interactiveshell.py in enable_matplotlib(self, gui)
3492 """
3493 from IPython.core import pylabtools as pt
-> 3494 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
3496 if gui != 'inline':
c:\users\diede\appdata\local\programs\python\python39\lib\site-packages\IPython\core\pylabtools.py in find_gui_and_backend(gui, gui_select)
278 """
--> 280 import matplotlib
282 if gui and gui != 'auto':
ModuleNotFoundError: No module named 'matplotlib'
I believe conda uses python 3.8 at present. If you look at the paths that are being searched in your error codes you’ll see it’s python 3.9 and unassociated with conda. Pretty sure you have more than distribution of Python on your system at present.
Either there’s some confusion on your PATH or you’re mixing up your installs and matplotlib is installed in a different location.
If you’re using conda then the Anaconda Prompt (cmd or powershell) will help you get a terminal with conda correctly sourced that should avoid this issue (use a conda environment and conda install to add packages).
If you’re using the other python install then it’ll likely be easier to installing everything via pip or similar.
Hi tgrtim, thanks for your reply. I will remove Python 3.9, as I have indeed installed 2 distributions of Python.
As a matter of fact, maybe it’s best to re-install python and anaconda.
Cheers!
Hi trgtim, I just reinstalled Python (3.9.4), Miniconda 4.9.2, and in the conda prompt I installed matplotlib. Everything done. And seems to be working.
The only thing that’s a bit annoying is that it seems you have to close the jupyter notebook and the miniconda prompt to be able to install packagages like mpl_toolkits.mplot3d. Is there any way around this, so you can install while you’re working in jupyter notebook?
I can’t say I’ve tried it often but I’d hazard a guess you could open a separate prompt, activate the same environment, install there and then access the relevant modules without closing jupyter. The module look-up would only start when you choose to import (things that are already imported may cause problems like this, so importing matplotlib and then install a matplotlib extension without restarting might lead to some quirky behaviour).
It might be wiser to keep your notebook cells in a linear and re-usable condition, close the notebook, install a package, re-open it and simply use run to execute the previous code cells. There’s much less chance of something going inexplicably wrong this way.
This is probably not going to happen often. Ideally you install every package you need at roughly the same time when you set up the environment. There’s nothing explicitly wrong with installing modules as you need them but there’s a much higher chance of dependency conflicts. You’ll likely become familiar with what you need quite quickly so hopefully you’ll not run into this situation again
(if you do I’d still advocate for closing the notebook).