Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLL load failed: the specified module could not be found Windows 10 shell

I'm trying to run a Python script from the Windows shell, but when I do

python path\to\file\script.py

I get an error "DLL load failed: The specified module could not be found" and it traces back to the line where I import numpy.

C:\Users\Admin>python path\to\file\script.py
Traceback (most recent call last):
  File "path\to\file\script.py", line 8, in <module>
    import numpy as np
  File "C:\Users\Admin\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\Users\Admin\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.

The weird part is that when I run it in an editor like Spyder, numpy imports just fine. Can someone help me?

Thanks

like image 261
Jack Hanson Avatar asked Sep 22 '19 23:09

Jack Hanson


People also ask

How do you fix DLL load failed the specified module could not be found?

importerror: dll load failed: The specified module could not be found error occurs because of the incompatibilities of Microsoft Visual C++ (Visual Studio) versions. The best way to fix this error (importerror: dll load failed) is to reinstall/ install the Microsoft Visual C++ distribution.

How can I fix Importerror DLL load failed the specified module could not be found in Python 3?

Reinstall Library. In most cases, the error occurs when you import a library. The cause of the error may be incorrect/incomplete installation or incompatibility of the library. In this case, you can try reinstalling the library to see whether the problem can be solved.


2 Answers

It's fixed Anaconda path issue. Check your %PATH% if it's correctly defined.

Source: https://github.com/numpy/numpy/issues/12957

like image 192
Valijon Avatar answered Oct 11 '22 04:10

Valijon


This is a common problem when installing python packages, mainly in windows.

Numpy and other packages have bindings to C++ code that require some special dependencies.

Rather than trying to get the dependencies exactly right for compiling the package, you can use a precompiled "wheel" file from one of several sources.

I use Chris Gholke's site

download the .whl file and install using

pip install directory/path/package.whl

edit: and as a note, the python environment you access from powershell or cmd is different from the anaconda environment in spyder. One of the differences between conda and pip is that conda installed precompiled packages while pip does not.

like image 26
Hugh_Kelley Avatar answered Oct 11 '22 02:10

Hugh_Kelley