The Python module “psutil” failed to build on Wind

2019-09-14 22:42发布

问题:

I set up VS 2008 SP1 on Windows 7 (64-bit) and tried to build the psutil, got the following error. VS 2008 is properly setup and with SP1 successfully patched.

I ran the "python setup.py build" command per the INSTALL file in the package.

c:\src\psutil>python setup.py build --verbose
running build
running build_py
running build_ext
building '_psutil_mswindows' extension
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo
/INCREMENTAL:NO /LIBPATH:C:\python_26_amd64\files\libs /LIBPATH:C:\python_26_amd
64\files\PCbuild\amd64 psapi.lib kernel32.lib advapi32.lib shell32.lib netapi32.
lib iphlpapi.lib /EXPORT:init_psutil_mswindows build\temp.win-amd64-2.6\Release\
psutil/_psutil_mswindows.obj build\temp.win-amd64-2.6\Release\psutil/_psutil_com
mon.obj build\temp.win-amd64-2.6\Release\psutil/arch/mswindows/process_info.obj
build\temp.win-amd64-2.6\Release\psutil/arch/mswindows/process_handles.obj build
\temp.win-amd64-2.6\Release\psutil/arch/mswindows/security.obj /OUT:build\lib.wi
n-amd64-2.6\_psutil_mswindows.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\psuti
l\_psutil_mswindows.lib /MANIFESTFILE:build\temp.win-amd64-2.6\Release\psutil\_p
sutil_mswindows.pyd.manifest
   Creating library build\temp.win-amd64-2.6\Release\psutil\_psutil_mswindows.lib and object build\temp.win-amd64-2.6\Release\psutil\_psutil_mswindows.exp_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__Py_BuildValue referenced in function _get_system_uptime
process_info.obj : error LNK2001: unresolved external symbol __imp__Py_BuildValue
process_handles.obj : error LNK2001: unresolved external symbol __imp__Py_BuildValue
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyBool_FromLong referenced in function _pid_exists
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTuple referenced in function _pid_exists
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyList_Append referenced in function _get_pid_list
process_info.obj : error LNK2001: unresolved external symbol __imp__PyList_Append
process_handles.obj : error LNK2001: unresolved external symbol __imp__PyList_Append
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyList_New referenced in function _get_pid_list_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp___Py_NoneStruct referenced in function _kill_process
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetFromWindowsErr referenced in function _kill_process
process_info.obj : error LNK2001: unresolved external symbol __imp__PyErr_SetFromWindowsErr
security.obj : error LNK2001: unresolved external symbol __imp__PyErr_SetFromWindowsErr
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyInt_FromLong referenced in function _process_wait
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyEval_RestoreThread referenced in function _process_wait
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyEval_SaveThread referenced in function _process_wait
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyErr_Clear referenced in function _get_process_cmdline
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyUnicodeUCS2_AsUTF8String referenced in function _get_process_cwd
process_info.obj : error LNK2001: unresolved external symbol __imp__PyUnicodeUCS2_AsUTF8String
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyUnicodeUCS2_FromWideChar referenced in function _get_process_cwd
process_info.obj : error LNK2001: unresolved external symbol __imp__PyUnicodeUCS
2_FromWideChar
process_handles.obj : error LNK2001: unresolved external symbol __imp__PyUnicodeUCS2_FromWideChar
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyExc_TypeError referenced in function _get_process_connections
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetString referenced in function _get_process_connections
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyExc_NotImplementedError referenced in function _get_process_connections
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyTuple_New referenced in function _get_process_connections
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PySequence_Contains referenced in function _get_process_connections
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PySequence_Check referenced in function _get_process_connections
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyLong_FromLong referenced in function _get_process_connections
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp___Py_ZeroStruct referenced in function _is_process_suspended
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp___Py_TrueStruct referenced in function _is_process_suspended
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyDict_SetItem referenced in function _get_network_io_counters
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyUnicodeUCS2_FromObject referenced in function _get_network_io_counters
process_info.obj : error LNK2001: unresolved external symbol __imp__PyUnicodeUCS2_FromObject
process_handles.obj : error LNK2001: unresolved external symbol __imp__PyUnicodeUCS2_FromObject
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyExc_RuntimeError referenced in function _get_network_io_counters
process_info.obj : error LNK2001: unresolved external symbol __imp__PyExc_RuntimeError
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyDict_New referenced in function _get_network_io_counters
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyDict_SetItemString referenced in function _get_disk_io_counters
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddIntConstant referenced in function _init_psutil_mswindows
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__PyErr_NewException referenced in function _init_psutil_mswindows
_psutil_mswindows.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4 referenced in function _init_psutil_mswindows
_psutil_common.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetObject referenced in function _NoSuchProcess
_psutil_common.obj : error LNK2019: unresolved external symbol __imp__PyObject_CallFunction referenced in function _NoSuchProcess
_psutil_common.obj : error LNK2019: unresolved external symbol __imp__PyExc_OSError referenced in function _NoSuchProcess
process_info.obj : error LNK2019: unresolved external symbol __imp__PyErr_Format referenced in function _get_process_info
build\lib.win-amd64-2.6\_psutil_mswindows.pyd : fatal error LNK1120: 34 unresolved externals
error: command '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe"' failed with exit status 1120

Any ideas which library is missing from the default distutils config? How can I successfully build psutil in my environment?

回答1:

For the benefit of other people with the same problem: make sure to use the Visual Studio x64 command prompt for launching the setup script.