I met this:
ImportError: MemoryLoadLibrary failed loading psutil\_psutil_windows.pyd
It is a little bit different from the question in filename.
After reading the source code of psutil, I figured out the root cause:
The target Windows platform of psutil depends on which platform it is built
on.
The following code exists in _psutil_windows.c, suggesting GetIfEntry2 is referenced. You can easily confirm this by running depends.exe to load _psutil_windows.pyd on Windows XP.
#if (_WIN32_WINNT >= 0x0600) // Windows Vista and above
SecureZeroMemory((PVOID)pIfRow, sizeof(MIB_IF_ROW2));
pIfRow->InterfaceIndex = pCurrAddresses->IfIndex;
dwRetVal = GetIfEntry2(pIfRow);
#else // Windows XP
pIfRow->dwIndex = pCurrAddresses->IfIndex;
dwRetVal = GetIfEntry(pIfRow);
#endif
And setup.py generates macros according to the current system environment like this:
# Windows
if WINDOWS:
def get_winver():
maj, min = sys.getwindowsversion()[0:2]
return '0x0%s' % ((maj * 100) + min)
macros.extend([
# be nice to mingw, see:
# http://www.mingw.org/wiki/Use_more_recent_defined_functions
('_WIN32_WINNT', get_winver()),
('_AVAIL_WINVER_', get_winver()),
('_CRT_SECURE_NO_WARNINGS', None),
# see: https://github.com/giampaolo/psutil/issues/348
('PSAPI_VERSION', 1),
])
So the options to solve this problem are:
- Build psutil on a Windows XP Machine, or
- Modify setup.py to use the target Windows platform version as we want.