38

In Windows, I created a Conda virtual environment with the command

conda create -n test python=2.7 pandas scipy matplotlib numpy

Once it is created, I activated the virtual environment and went into a python interpreter. When trying to import numpy, I get the following error:

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda3\envs\test\lib\site-packages\numpy\__init__.py", line 180, in <module>
    from . import add_newdocs
  File "C:\Anaconda3\envs\test\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Anaconda3\envs\test\lib\site-packages\numpy\lib\__init__.py", line 8,
 in <module>
    from .type_check import *
  File "C:\Anaconda3\envs\test\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Anaconda3\envs\test\lib\site-packages\numpy\core\__init__.py", line 14, in <module>
    from . import multiarray
ImportError: DLL load failed: The specified module could not be found.

Any ideas what is going on here? Thanks!

mkrems
  • 535
  • 1
  • 5
  • 9

6 Answers6

23

Uninstall and install numpy again.

pip uninstall numpy
pip install numpy

Then try import again, it should work. That is what I did

Victor O
  • 241
  • 2
  • 3
16

Unlike @Rafael, for me, libiomp5md.dll wasn't the issue. I installed Dependency Walker to investigate what was going on. Even though the dll versions were different, but Dependency Walker said it was okay.

What was wrong though, was that mkl_intel_thread.dll had warnings (red icon). If you're using Win 8++, ignore the api-win and ext-ms issues as Dependency Walker wasn't updated for new Windows versions and doesn't recognise Windows new APIs.

My solution is to copy all mkl_*.dlls from the former to the latter:

  • \Anaconda2\Library\bin
  • \Anaconda2\Lib\site-packages\numpy\core

I was able to import numpy and sklearn after that.

Cardin
  • 5,148
  • 5
  • 36
  • 37
  • 17
    I had the same error except for Anaconda3. I didn't have to move the dll files, but I added the path \Anaconda3\Library\bin to my Windows 10 path variable and then it worked. – Decrayer Nov 28 '18 at 15:17
  • me also (on win 8.1), does anyone know shat is going on? – Ray Tayek Feb 10 '19 at 09:24
  • 6
    In my case with Anaconda 3 and python 3.7 on Windows 10 adding the below 3 paths to the path variables helped: `C:\ProgramData\Anaconda3\Library\bin; C:\ProgramData\Anaconda3\Scripts; C:\ProgramData\Anaconda3 ` – Martin Petrov Apr 02 '19 at 18:26
9

It seems the proper way to fix this is to do:

conda install msvc_runtime

If you are in a virtual environment, add this package there.

cfh
  • 4,576
  • 1
  • 24
  • 34
  • This way helped me to solve the problem described in the question. I got the error when tried to run a script in a virtual environment created by Miniconda3 (Python 3.6, Win10 x64). Python and many libraries were downgraded. –  Mar 13 '19 at 10:04
  • Thanks a ton..this works esp if one has simple python virtual env and not conda...windows python is still a pain if u don't have latest libraries. numpy install..uninstall didn't help. msvc helped. You saved me from spending more time..Thank you. – Binu Jul 25 '19 at 20:24
  • 1
    PackagesNotFoundError: The following packages are not available from current channels: - msvc_runtime Current channels: - https://repo.anaconda.com/pkgs/main/win-32 - https://repo.anaconda.com/pkgs/main/noarch - https://repo.anaconda.com/pkgs/r/win-32 - https://repo.anaconda.com/pkgs/r/noarch - https://repo.anaconda.com/pkgs/msys2/win-32 - https://repo.anaconda.com/pkgs/msys2/noarch – CS QGB Jan 28 '20 at 03:23
  • 1
    now it 's conda install -c free msvc_runtime – aa bb Feb 22 '21 at 00:18
  • 1
    @aabb This gave me package conflicts unfortunately. – barnhillec Feb 24 '21 at 20:36
  • Neither `conda install` nor `conda install -c free` works for me. – Ilya Feb 28 '22 at 16:50
  • Thank you so much! after many attempts installing MSC++ and plaing with PATH this was the only that worked. – Alejandro Rubio Aug 27 '23 at 11:16
5

For my case, I have also the import numpy DLL error in anaconda3, and Decrayer (Nov 28) provided the best solution: I had the same error except for Anaconda3: just added the path \Anaconda3\Library\bin to your Windows 10 path variable and then it worked.

I have been trying to install anaconda3.7.1 or 3.7.0 without luck, going to full length of restarting the PC after the key steps to make sure the DLL is no longer in use in memory. Ultimately, thanks to decrayer, now numpy works for me!

HAltos
  • 701
  • 7
  • 6
5

For me this was solved by adding the following paths to my system path variable.

C:\Users\UserName\Anaconda3\
C:\Users\UserName\Anaconda3\bin
C:\Users\UserName\Anaconda3\Scripts
C:\Users\UserName\Anaconda3\Library\mingw-w64\bin (not strictly necessary)
C:\Users\UserName\Anaconda3\Library\bin

Before adding them explicitly in the system path variable, you can perform a test by adding these paths temporarily:

base_path = r"C:\Users\UserName\Anaconda3"
path = os.pathsep.join([os.path.join(base_path, i) for i in [r"", r"bin", r"Scripts", r"Library\mingw-w64\bin", r"Library\bin"]])
os.environ["PATH"]+=os.pathsep+path

Thanks to this post on PyCharm support.

BDeforce
  • 73
  • 2
  • 7
3

For the record, I had the same error here (Python 3.5 64-bit on Windows 10), and this page helped me find the solution. The problem was a conflict with libiomp5md.dll, which existed on two locations:

  • C:\Windows\System32\libiomp5md.dll
  • C:\Anaconda3\Library\bin\libiomp5md.dll

Python was trying to use the version in System32 folder, which was an old version. I removed it (renamed) and now it uses the correct version, on Anaconda3 folder, and now I can import numpy without the import error.

Rafael Monteiro
  • 4,509
  • 1
  • 16
  • 28