Trying to solve WindowError 126 - module not found

Although this is my first question on StackOverflow, I consider myself a long time member of the community.

Considering myself as a pre-season programmer, I'll try to be as specific as possible.

I am writing a Python package that uses a C dll to load image files using ctypes. I am using Python 3.3.5 32bits version for Windows 8 x64. I had to build a dll from C code. The dll is stb_image.h which is available on GitHub . I used Code :: Blocks version 13.12 with the GCC compiler. The dll seems to build fine.

By my definition, the dll should be in the same folder as the py code file that wraps its functions, but when ctypes tries to load the DLL, an exception is thrown: [in] known WindowsError: [Error 126] Module not found.

I found several similar questions and tried to find solutions

  • adding dll path via os.environ['PATH']

  • adding dll path manually in Path environment variable

  • changing the current working directory with os.chdir()

  • using the module attribute file to find the library

none of them solved the problem

The stb_image library itself has no dependencies, so I don't understand why windows can't find it, since the dll is where it should be and the path is pointing to the exact location. And of course, there are many other ways to make the job work: PyGame, pySFML (which also uses stb_image), PIL, PyPng, PySDL, you name it, but I do it mostly for educational purposes.

While writing this question, something popped into my head (which may or may not have anything to do with the problem): whenever I compile and link programs with GCC and try to run them, I got a window saying that some dll ( libgcc.dll or something like that) was not found. Could this be the reason that Windows cannot load stb_image.dll?

I tried everything I allowed me to do to fix this problem, but it wasn't enough. Could you guys tell me about this?

PS: Sorry for any bad english. I am natural from Brazil.

+3


source to share





All Articles