Numpy: ImportError: DLL load failed for numpy 1.16.1

Created on 12 Feb 2019  ·  21Comments  ·  Source: numpy/numpy

Create fresh virtual env with Anaconda Navigator 1.9.6 under Windows 10, selecting Python 3.7, naming python37

In the console of VSCode:

  • activate python37
  • pip install numpy
(python37) D:\TfsProj\alphastone>pip install numpy
Collecting numpy
  Using cached https://files.pythonhosted.org/packages/41/b8/3a6b07352c2542ca1c89be7583e7ca07bf513895b6ac59ae008054f326b1/numpy-1.16.1-cp37-cp37m-win_amd64.whl
Installing collected packages: numpy
Successfully installed numpy-1.16.1

(same with parameter --no-cache-dir)

  • python
  • import numpy
(python37) D:\TfsProj\alphastone>python
Python 3.7.2 (default, Feb 11 2019, 14:11:50) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "C:\Users\Name\.conda\envs\python37\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
    from . import multiarray
  File "C:\Users\Name\.conda\envs\python37\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Users\Name\.conda\envs\python37\lib\site-packages\numpy\core\overrides.py", line 6, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Name\.conda\envs\python37\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Users\Name\.conda\envs\python37\lib\site-packages\numpy\core\__init__.py", line 47, in <module>
    raise ImportError(msg)
ImportError:

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

All advices, reinstallations via pip and conda, or different numpy versions (e.g. 1.15.4) didn't solve this issue for me.

If I do multiple pip uninstall numpy until there is no numpy left, and then do a conda install numpy, importing numpy interestingly works (in 1.15.4).

A conda install numpy does the following:

The following NEW packages will be INSTALLED:

  blas               pkgs/main/win-64::blas-1.0-mkl
  icc_rt             pkgs/main/win-64::icc_rt-2019.0.0-h0cc432a_1
  intel-openmp       pkgs/main/win-64::intel-openmp-2019.1-144
  mkl                pkgs/main/win-64::mkl-2019.1-144
  mkl_fft            pkgs/main/win-64::mkl_fft-1.0.10-py37h14836fe_0
  mkl_random         pkgs/main/win-64::mkl_random-1.0.2-py37h343c172_0
  numpy              pkgs/main/win-64::numpy-1.15.4-py37h19fb1c0_0
  numpy-base         pkgs/main/win-64::numpy-base-1.15.4-py37hc3f5095_0

What's missing for the pip way?
Any ideas?

00 - Bug 29 - InteAnaconda

Most helpful comment

There is a difference between the location of the extra support libraries supplied with anaconda and those supplied with stock numpy that you get from pip install. This requires adjustments to the PATH variable. Perhaps the PATH adjustments are failing at import. Does the site-packages\numpy\.libs directory exist and does it contain *.dll files?, If so, can you try to prepend that directory to your PATH before running python:

rem This fails
python -c "import numpy"

rem Does this succeed ??? 
PATH=path\to\site-packages\numpy\.libs;%PATH%
python -c "import numpy"

Please report back to us if that directory exists and if changing the path succeeds, it indicates the code in numpy\__config__.py is failing to modify the os.environ['PATH']. Maybe you have exceeded the allowed PATH length, or there is some other problem with your PATH environment variable.

Anaconda places the extra dlls in <anaconda install>\Library\bin, and adds that directory to the path when you activate a anaconda environment. Stock numpy, as described above, tries to append the .lib directory to the end of the PATH variable.

All 21 comments

There is a difference between the location of the extra support libraries supplied with anaconda and those supplied with stock numpy that you get from pip install. This requires adjustments to the PATH variable. Perhaps the PATH adjustments are failing at import. Does the site-packages\numpy\.libs directory exist and does it contain *.dll files?, If so, can you try to prepend that directory to your PATH before running python:

rem This fails
python -c "import numpy"

rem Does this succeed ??? 
PATH=path\to\site-packages\numpy\.libs;%PATH%
python -c "import numpy"

Please report back to us if that directory exists and if changing the path succeeds, it indicates the code in numpy\__config__.py is failing to modify the os.environ['PATH']. Maybe you have exceeded the allowed PATH length, or there is some other problem with your PATH environment variable.

Anaconda places the extra dlls in <anaconda install>\Library\bin, and adds that directory to the path when you activate a anaconda environment. Stock numpy, as described above, tries to append the .lib directory to the end of the PATH variable.

You method indeed works!
C:\Users\Name.conda\envs\test37\Lib\site-packages\numpy.libs exists and there is one file in it:
libopenblas.IPBC74C7KURV7CB2PKT5Z5FNR3SIBV4J.gfortran-win_amd64.dll

I will try a fresh install with a shorter initial path to verify your theroy in about an hour.

Side question: Shouldn't there be more dlls in that path? I want to use OpenMP and mkl with pytorch, not openblas...

If you want to use mkl, then use conda, not pip

sorry, use pip install intel-numpy not pip install numpy, but you will get numpy 1.15.1. Conda makes it easier, and it seems you are using anaconda, so probably sticking with conda will give you a more unified experience.

Ok I shortened my PATH and it's still not working with "pip install numpy".
This is prepended to my PATH if I "conda activate test37":
PATH=C:\Users\Name.conda\envs\test37;C:\Users\Name.conda\envs\test37\Library\mingw-w64\bin;C:\Users\Name.conda\envs\test37\Library\usr\bin;C:\Users\Name.conda\envs\test37\Library\bin;C:\Users\Name.conda\envs\test37\Scripts;C:\Users\Name.conda\envs\test37\bin;...

My PATH is still long, but I can't remove anything from it anymore, because other tools need it like it is.

Why is there no conda numpy 1.16.1?

Thanks for your help, mate!

(test37) D:\test>pip install intel-numpy

Collecting intel-numpy
Could not find a version that satisfies the requirement intel-numpy (from versions: )
No matching distribution found for intel-numpy

"conda install numpy" gives me 1.15.4 which is working fine.

@mattip THANK YOU VERY MUCH

Maybe we should statically link and alleviate the need for this path mangling

Could this PATH editing issue in numpy for newer python versions have the same reason?
https://github.com/pytorch/pytorch/issues/4518#issuecomment-463224849 -> https://github.com/pytorch/pytorch/issues/17051

I got the same type of error for scipy as well. After creating an env using conda I had to uninstall using pip and install using conda for all packages that created an issue for me. That worked for me, although it's not an ideal solution since this was a very manual operation.

@djdookie: just to be sure what worked and what didn't. You have the dll in C:\Users\Name.conda\envs\test37\Lib\site-packages\numpy.libs. Prepending that to PATH before starting python worked. Could you try appending that to the end of PATH (with a ';' seperator) and testing if a pip-installed numpy works (maybe in a new conda environment, which would change the path)?

Edit: note that the new environment would have a different path-to-dll

It seems this is a broken ananconda, see this issue ContinuumIO/anaconda-issues#10628

Closing. Anaconda seems to have fixed the issue that caused this.

I just downloaded the newest windows version of conda for python3.7 for windows 7 and got this issue. Can we reopen?

I solve the problem. It was a path issue as I was using WingIDE. I used these instructions to fix
https://wingware.com/blog/anaconda

Specifically, I opened the anaconda command prompt and did "PATH" and copied it into my wing path for my project.

For reference, my PATH=C:\Users\xx\AppData\Local\Continuum\anaconda3;C:\Users\xx\AppData\Local\Continuum\anaconda3\Library\mingw-w64\bin;C:\Users\xx\AppData\Local\Continuum\anaconda3\Library\usr\bin;C:\Users\xx\AppData\Local\Continuum\anaconda3\Library\bin;C:\Users\xx\AppData\Local\Continuum\anaconda3\Scripts;C:\Users\xx\AppData\Local\Continuum\anaconda3\bin;C:\Users\xx\AppData\Local\Continuum\anaconda3\condabin;

I just went to the folder and deleted one. That seems to have fixed it.

This also seems to happen in Jupyter if you do not "conda activate" the environment that you will be using PRIOR to starting Jupyter.

And it also happens in VS Code if you don't "conda activate" the environment PRIOR to starting vs code. If I use "code ." in the conda environment prompt, it works.

This also seems to happen in Jupyter if you do not "conda activate" the environment that you will be using PRIOR to starting Jupyter.

This worked for me. And the issue seems to particularly in jupyter lab

I solved my issues with Numpy DLL load issues by replacing Anaconda3 with WinPython.

I have this issue with WinPaython

Was this page helpful?
0 / 5 - 0 ratings