Juoyterlab & Anaconda error when trying to import matplotlib

Hello,

I am a new learner. I am getting familiarized with python, Anacoda (env) and coding in general. I am taking a python online course, and we have a simple test of trying Jupyterlab, but when I tried to run the code I get an error.

The code I am trying to run is:

a={1,2,3,4}
b={-1,-2,-3,-4}
import matplotlib.pyplot as plt

but I get a very long error. I tried:

  1. uninstall and install anaconda
  2. use jupyterlab online
  3. install jupyterlab desktop

Until now nothing works. The error I get is:

ModuleNotFoundError Traceback (most recent call last)
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\core_init_.py:24
23 try:
—> 24 from . import multiarray
25 except ImportError as exc:

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\core\multiarray.py:10
9 import functools
—> 10 from . import overrides
11 from . import _multiarray_umath

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\core\overrides.py:8
7 from …_utils._inspect import getargspec
----> 8 from numpy.core._multiarray_umath import (
9 add_docstring, _get_implementing_args, _ArrayFunctionDispatcher)
12 ARRAY_FUNCTIONS = set()

ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath’

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy_init_.py:144
143 try:
→ 144 from numpy.config import show as show_config
145 except ImportError as e:

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy_config_.py:4
3 from enum import Enum
----> 4 from numpy.core._multiarray_umath import (
5 cpu_features,
6 cpu_baseline,
7 cpu_dispatch,
8 )
10 all = [“show”]

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\core_init_.py:50
27 msg = “”"
28
29 IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
(…)
48 “”" % (sys.version_info[0], sys.version_info[1], sys.executable,
49 version, exc)
—> 50 raise ImportError(msg)
51 finally:

ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.9 from “C:\Users\moniq\anaconda3\envs\env1\python.exe”
  • The NumPy version is: “1.26.1”

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named ‘numpy.core._multiarray_umath’

The above exception was the direct cause of the following exception:

ImportError Traceback (most recent call last)
Cell In[2], line 1
----> 1 import matplotlib.pyplot as plt

File ~\anaconda3\envs\env1\lib\site-packages\matplotlib_init_.py:156
153 import tempfile
154 import warnings
→ 156 import numpy
157 from packaging.version import parse as parse_version
159 # cbook must import matplotlib only within function
160 # definitions, so it is safe to import from it here.

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy_init_.py:149
145 except ImportError as e:
146 msg = “”“Error importing numpy: you should not try to import numpy from
147 its source directory; please exit the numpy source tree, and relaunch
148 your python interpreter from there.”“”
→ 149 raise ImportError(msg) from e
151 all = [
152 ‘exceptions’, ‘ModuleDeprecationWarning’, ‘VisibleDeprecationWarning’,
153 ‘ComplexWarning’, ‘TooHardError’, ‘AxisError’]
155 # mapping of {name: (value, deprecation_msg)}

ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.

I tied many things more but I think I ended up making everything worst.
Please let me know if you have an idea of how I can fix this problem.

Thank you in advance