[Python-Dev] Python 2.7.3 shared library, like _socket.pyd, cannot be loaded

Terry Tang terry_tang2005 at yahoo.com
Wed Apr 25 20:41:33 CEST 2012


Hi There,

I am integrating Python 2.7.3 into our system on Windows. We embedded Python 2.7.3 interpreter to our system.

The problem we met is, our extended Python interpreter cannot load "_socket.pyd" when "import socket" is executed, for example. Here is the error:

Traceback (most recent call last):
  File "t.py", line 1, in <module>
    import socket;
  File "C:\trunk1\third_party\python-2.7.3\win32\lib\socket.py", line 47, in <mo
dule>
    import _socket
ImportError: DLL load failed: The specified module could not be found.


I wrote a small program as listed below to manually load "_socket.pyd" from Python 2.7.3 binary installation  on Windows, and got the same failure.

static void TestDllLoad(const char *dllPath)
{
    HINSTANCE socketh=LoadLibraryEx(dllPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
    if (socketh == NULL) {

fprintf(stderr, "Failed to load shared library: %s\nError: %d\n", dllPath,  GetLastError());
    } else {
fprintf(stderr, "Successfully load shared library: %s\n", dllPath);
    }
}

int main()
{
    /* The following loading success. */
    TestDllLoad("<PathToPython2.3.3>\\DLLs\\_socket.pyd");
    /* The following loading failed. */
    TestDllLoad("<PathToPython2.7.3>\\DLLs\\_socket.pyd");
    return 0;}

I tried MSVC 2008 and a third-party compiler, and got the same result, even after copying "python27.dll" to the testing directory from Python 2.7.3 installation on Windows.

There is a similar failure reported in http://bugs.python.org/issue4566, but it is marked as fixed and closed. 

Anyone has any idea about the problem?

Thanks a lot.

-Terry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120425/32555bf4/attachment-0001.html>


More information about the Python-Dev mailing list