Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: DLL load failed for numpy 1.16.1 #12957

Closed
djdookie opened this issue Feb 12, 2019 · 24 comments
Closed

ImportError: DLL load failed for numpy 1.16.1 #12957

djdookie opened this issue Feb 12, 2019 · 24 comments

Comments

@djdookie
Copy link

djdookie commented Feb 12, 2019

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?

@mattip
Copy link
Member

mattip commented Feb 12, 2019

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.

@djdookie
Copy link
Author

djdookie commented Feb 12, 2019

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...

@mattip
Copy link
Member

mattip commented Feb 12, 2019

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

@mattip
Copy link
Member

mattip commented Feb 12, 2019

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.

@djdookie
Copy link
Author

djdookie commented Feb 12, 2019

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!

@djdookie
Copy link
Author

djdookie commented Feb 12, 2019

(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.

@indramal
Copy link

@mattip THANK YOU VERY MUCH

@mattip
Copy link
Member

mattip commented Feb 13, 2019

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

@djdookie
Copy link
Author

djdookie commented Feb 13, 2019

Could this PATH editing issue in numpy for newer python versions have the same reason?
pytorch/pytorch#4518 (comment) -> pytorch/pytorch#17051

@ivarstange
Copy link

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.

@mattip
Copy link
Member

mattip commented Feb 14, 2019

@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

@mattip
Copy link
Member

mattip commented Feb 14, 2019

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

@mattip
Copy link
Member

mattip commented Mar 6, 2019

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

@mattip mattip closed this as completed Mar 6, 2019
@isaacgerg
Copy link

isaacgerg commented Apr 25, 2019

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

@isaacgerg
Copy link

isaacgerg commented Apr 25, 2019

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;

@Akababa
Copy link

Akababa commented Sep 28, 2019

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

@jeffheaton
Copy link

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

@mKay00
Copy link

mKay00 commented Dec 18, 2019

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.

@opokualbert
Copy link

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

@TimoRiikonen
Copy link

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

@stlweb
Copy link

stlweb commented May 7, 2020

I have this issue with WinPaython

@engsbk
Copy link

engsbk commented Feb 18, 2021

I have a similar problem:

  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\numpy\core\__init__.py", line 48, in <module>
    raise ImportError(msg)
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.7 from "C:\Users\User\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe"
  * The NumPy version is: "1.19.5"

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: The specified module could not be found.

Does anyone have a suggestion on how to solve?
My tf version is 2.3
My numpy version is 1.19
my python version is 3.7

Thanks!

@IKsares
Copy link

IKsares commented Feb 23, 2021

I'm having the same issue. This happened after installing scipy. How do I edit my PATH variable?

@iamMeshi
Copy link

iamMeshi commented Feb 23, 2021

I'm having the same issue. This happened after installing scipy. How do I edit my PATH variable?

The only thing that solved this issue for me was to upgrade the libaries in this order. Uninstalling them and reinstalling them didn't work, I had to use --upgrade. Here's the link:

https://stackoverflow.com/a/50792985/9134698

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests