2

I am trying to load a DLL from Python, but get WindowsError: [Error 126] The specified module could not be found.

import ctypes
my_dll = "C:/smt/toolbox/dlls/NMSim_Libraries.dll"
nmsim = ctypes.cdll.LoadLibrary(my_dll)

When I used Dependency Walker, it states that 3 dependencies are missing, all of which are in the path: "C:\Users\skeyel\AppData\Local\Continuum\Anaconda2\Lib\site-packages\numpy\core"

I tried adding this path to the system path using:

import sys
sys.path.append("C:\\Users\\skeyel\\AppData\\Local\\Continuum\\Anaconda2\\Lib\\site-packages\\numpy\\core\\")

but this did not solve the problem. How do I get the .dll to communicate with the dependencies?

NOTES:

  1. There are two Python installations on my computer: 2.7.8 that shipped with ArcGIS and 2.7.11 that shipped with Anaconda. It runs fine when run through the Spyder IDE that came with the Anaconda installation.

  2. It runs fine on my laptop (on both 2.7.8 and 2.7.11).

  3. I've checked and/or tried a variety of things based on the advice from: WindowsError: [Error 126] The specified module could not be found

    3a. The dll exists and the path to the dll is correct, as it works for one version when I copy and paste the exact same code

    3b. the DLL and Python are both set up for 32 bits (note: the OS is 64 bit). Using import platform followed by platform.architecture() gives both versions as 32-bit.

    3c. I have tried adjusting sys.path to include the same paths between the two installations

    3d. I have tried os.chdir() to change to the .dll directory, and then just loading the dll by name with no path information

    3e. I have tried copying and pasting the listed missing dependencies into the same folder as the .dll

  4. I tried copying, pasting and running the (minimally modified) code from selected answer here: Python | accessing dll using ctypes

Here is the full traceback:

Runtime error 
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\skeyel\AppData\Local\Continuum\Anaconda2\Lib\ctypes\__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
File "C:\Users\skeyel\AppData\Local\Continuum\Anaconda2\Lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

It seems like there is something simple that I'm missing - anyone know what it is?

Many thanks.

Community
  • 1
  • 1
Sasha
  • 21
  • 1
  • Note that `sys.path.append` does not append the path given as an argument to the environment variable __PATH__, but rather to _Python_'s modules search path (__PYTHONPATH__ ). Try using `os.environ["PATH"]`, or even better, set the __PATH__ variable before launching the interpreter. – CristiFati Aug 22 '16 at 19:27

1 Answers1

0

The problem was solved by re-installing Anaconda https://www.continuum.io/downloads.

I still have no idea what the specific problem was.

Sasha
  • 21
  • 1