The output from listdlls.exe shows that there's no problem loading the dependency ws2_32.dll (Winsock), which would be surprising to say the least. So the problem is that it's trying to load the wrong _socket.pyd.
In the comments it was confirmed that loading _socket.pyd worked when an absolute path was passed to imp.load_dynamic
. It turns out that the system had the environment variable PYTHONPATH
set to include C:\Python27\DLLs
. The solution was to simply unset this environment variable.
I was thrown off by the error message. Normally such a case would raise an error that the shared library is compiled for a different Python version. However, _socket.pyd for Python 2.7 links with msvcr90.dll. This DLL isn't on the DLL search path. It's in a subdirectory of %windir%\WinSxS
. It's found by consulting the activation context of C:\Python27\python.exe
, which specifies the C runtime dependency in its embedded manifest:
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.VC90.CRT"
version="9.0.21022.8"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b">
</assemblyIdentity>
</dependentAssembly>
</dependency>
So when running under C:\Python33\python.exe
, trying to load the 2.7 _socket.pyd raises the following exception:
>>> imp.load_dynamic('_socket', r'C:\Python27\DLLs\_socket.pyd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
3.3 and 3.4 are built with Visual Studio 2010 instead of 2008, which switched back to installing msvcr100.dll on the normal search path. So for comparison here's the error I get when I try to import the 3.3 version of _socket.pyd
within 3.4:
>>> imp.load_dynamic('_socket', r'C:\Python33\DLLs\_socket.pyd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: Module use of python33.dll conflicts with this version of Python.