jupyter notebook calls numpy and reports an error: Importing the numpy C-extensions failed.

created at 07-30-2021 views: 21

Error message

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.8 from "D:\miniconda3\envs\cv38\python.exe"
* The NumPy version is: "1.20.3"

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

Original error was: DLL load failed while importing _multiarray_umath: module could not be found.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
D:\miniconda3\envs\cv38\lib\site-packages\numpy\core\__init__.py in <module>
     21 try:
---> 22     from . import multiarray
     23 except ImportError as exc:

D:\miniconda3\envs\cv38\lib\site-packages\numpy\core\multiarray.py in <module>
     11 
---> 12 from . import overrides
     13 from . import _multiarray_umath

D:\miniconda3\envs\cv38\lib\site-packages\numpy\core\overrides.py in <module>
      6 
----> 7 from numpy.core._multiarray_umath import (
      8     add_docstring, implement_array_function, _get_implementing_args)

ImportError: DLL load failed while importing _multiarray_umath: module could not be found.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-a725c2af9d26> in <module>
----> 1 import torch
      2 
      3 print(torch.__version__)

D:\miniconda3\envs\cv38\lib\site-packages\torch\__init__.py in <module>
    603 
    604 # Shared memory manager needs to know the exact location of manager executable
--> 605 _C._initExtension(manager_path())
    606 del manager_path
    607 

D:\miniconda3\envs\cv38\lib\site-packages\torch\cuda\__init__.py in <module>
    605 from . import profiler
    606 from . import nvtx
--> 607 from . import amp

D:\miniconda3\envs\cv38\lib\site-packages\torch\cuda\amp\__init__.py in <module>
----> 1 from .autocast_mode import autocast, custom_fwd, custom_bwd  # noqa: F401
      2 from .grad_scaler import GradScaler  # noqa: F401

D:\miniconda3\envs\cv38\lib\site-packages\torch\cuda\amp\autocast_mode.py in <module>
      4 import collections
      5 try:
----> 6     import numpy as np
      7     HAS_NUMPY = True
      8 except ModuleNotFoundError:

D:\miniconda3\envs\cv38\lib\site-packages\numpy\__init__.py in <module>
    143     from . import _distributor_init
    144 
--> 145     from . import core
    146     from .core import *
    147     from . import compat

D:\miniconda3\envs\cv38\lib\site-packages\numpy\core\__init__.py in <module>
     46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
     47         __version__, exc)
---> 48     raise ImportError(msg)
     49 finally:
     50     for envkey in env_added:

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.8 from "D:\miniconda3\envs\cv38\python.exe"
  * The NumPy version is: "1.20.3"

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

Original error was: DLL load failed while importing _multiarray_umath: module could not be found.

solution

At this point, use the conda list | grep numpy command to check the numpy version and find that it has become the pip installation version.

Restart jupyter notebook and then you can run the program.

created at:07-30-2021
edited at: 07-30-2021: