Re: [Cython] ImportError: DLL load failed: The specified module could not be found.

2,404 views
Skip to first unread message

mark florisson

unread,
Oct 21, 2011, 4:03:07 PM10/21/11
to Core developer mailing list of the Cython compiler, cython...@googlegroups.com
Sorry, most of us don't use Windows. In any case, this is something
that belongs on the cython-users list, please continue the discussion
there.

On 21 October 2011 20:51, Adrian Martínez Vargas <adrian...@yahoo.es> wrote:
> I'm 90% sure that the problem is that the pyd file is not registered (it
> works if I put the module in my working directory). I'm trying to registered
> in windows 7  with regsvr32 but don't work.
>
> I need HELP guys!
>
> Regards
> Adrian
>
> On 19/10/2011 12:45 PM, Alexander T. Berghage wrote:
>>
>> Adrian
>>
>> I'm a little unclear on the big picture here. Are you trying to
>> distribute a module (a .pyd / .dll) that you or someone else can
>> import from a .py script, or are you looking to compile a .exe that
>> runs your cython code on execution?
>>
>> ----
>>
>> Just interpreting the error you're describing (ImportError: DLL load
>> failed: could not be found),  the dynamic linker couldn't find a
>> library it needed. Most likely this is either a symptom of missing
>> dependencies or a path problem. Here's my suggestions for diagnosing
>> and fixing the problem:
>>
>> Missing Dependencies:
>>     One very simple way to confirm that all the dependencies of your
>> cython module are
>>     available is to point the dependency walker utility[1] at it, and
>> look for missing DLLs.
>>
>> Directory Structure:
>>     Is the .pyd file you built from your cython module in the
>> PYTHONPATH (or your current
>>     working directory? If it's not, there's your issue.
>>
>> [1]  http://www.dependencywalker.com/
>>
>>
>> Hope that helps!
>>
>> Best,
>> -Alex
>> _______________________________________________
>> cython-devel mailing list
>> cython...@python.org
>> http://mail.python.org/mailman/listinfo/cython-devel
>>
>
> _______________________________________________
> cython-devel mailing list
> cython...@python.org
> http://mail.python.org/mailman/listinfo/cython-devel
>

Adrian Martínez Vargas

unread,
Oct 21, 2011, 7:03:48 PM10/21/11
to cython...@googlegroups.com
Dear cython-users list,

I compiled and installed in Windows 7 a python module with these two commands
C:\Temporal\source\Cython_ext> python OK_setup_windows.py build_ext
C:\Temporal\source\Cython_ext> python OK_setup_windows.py install

The problem is (I think) that the pyd file is nor registered in the system. It runs only if the module is
in the working directory, as is shown below:
---------------------------------------------------------------------------------------------------------
In [5]: cd c:\
c:\

In [6]: import okriging_py as ok
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.


In [7]: cd C:\Python27\Lib\site-packages
C:\Python27\Lib\site-packages

In [8]: import okriging_py as ok

In [9]:
---------------------------------------------------------------------------------------------------------

my question are:
a) where is the problem
b) how to distribute my module without this (possible system configuration) error

Registering the module with regsvr32 doesn't


sorry about my ignorance (I am more Linux Debian user...)

Regards
Adrian

Robert Bradshaw

unread,
Oct 21, 2011, 8:59:03 PM10/21/11
to cython...@googlegroups.com

Sorry to keep bouncing you around from list to list, but if it works
on Linux and not in Windows (and it's not a compiler error in the
generated code) it's almost certainly not a Cython error. This is
actually good news, because the lists concerning distutils, etc. are
much more likely to have people knowledgeable about Windows than here
(we're almost all Linux/Mac users). I, personally, have absolutely no
idea.

You might want to provide your actual setup.py file (why do you have a
different one for Windows?) and compile the most trivial extension
(e.g. "print 'hello'").

That being said, if someone here does know, please speak up.

- Robert

Uwe Schmitt

unread,
Oct 22, 2011, 5:09:28 AM10/22/11
to cython-users
Maybe some runtime libraries are missing. I would download
http://www.dependencywalker.com/ and open the .pyd module with this
program. This should show you missing libs, which is the most
probable reason why loading fails on windows and not on linux.

In most cases some runtime libs from visualc like msvcrt??.dll are
missing.

Regards, Uwe

On 22 Okt., 01:03, Adrian Martínez Vargas <adriangeol...@yahoo.es>
wrote:

Adrian Martínez Vargas

unread,
Oct 25, 2011, 2:15:35 AM10/25/11
to cython...@googlegroups.com
Dear Uwe,

The module works if I execute python in the same directory where is the file *.pyd. The problems may be related to the linkage of the module by the system.

I don't know if I have to run the build and install commands to make it work or if I have t follow this ugly way I found in http://www.mingw.org/wiki/FAQ:
+++++++++++++++++++++++++++++++++++++++++++
  • How do I create Python extensions?
    • As of Python 2.5, the official distribution is built with MS-VC 2003. Python requires that all extensions be built with the same compiler. It is however possible to build such extensions using MinGW with the help of MSYS. Create a file called pydistutils.cfg in your home directory with the following contents.
[build] 		
compiler=mingw32
  • Next, use pexports to export the python dll symbols. The library can typically be found under C:\WINDOWS\system32. Use the following command.
pexports /c/WINDOWS/system32/python25.dll >py25.def
  • Then, use the following command to build an import library.
dlltool -D python25.dll -d python25.def -l libpython25.a
  • Move libpython25.a to /mingw/lib. You may need to add -I"/path/to/python/include" to the gcc command line. You can now build and install the extensions by following standard UNIX instructions under MSYS.
+++++++++++++++++++++++++++++++++++++++++++ 

Uwe Schmitt

unread,
Oct 25, 2011, 4:15:03 AM10/25/11
to cython-users
If your module is loaded in one setting and not in an other, it is not
an compiler compatibilty issue. Using the wrong compiler you get a
module
which can not be loaded at all, and in most cases you get some
crashing
python interpreter and not a clear error message.

The fact that you module can be loaded if you are in the "right"
directory,
indicates that you have a dependency to another shared library. So:
please use dependency walker and post the results.

Regards, Uwe

Reply all
Reply to author
Forward
0 new messages