When compiling certain C++ python extension included in standard libs, many users run into unresolved external symbol errors, especially under Windows. I do run into such an issue while trying to install the lib fairseq from facebook. And they don’t seem to be willing to fix it. So, the developers need to fix it by themselves.
The error that is triggered is the following:
module.obj : error LNK2001: unresolved external symbol __imp__PyModule_Create2
Can someone explain me what this __imp__PyModule_Create2 function does? And why is it missing from standard python libraries under Windows?
You are using a module that was compiled for a different version of python.
You need to have a version of the module that is compatible with the version of python you are using,
It is often the case that when a new version of python is released there is a time delay before modules are built and released from the new python version.
Interesting… I’ve tried to install fairseq with pip and didn’t get any warning about the version of python I am using. The documentation says that the minimum version is 3.8.
I tried with python versions 3.8 and 3.9 but it didn’t work better… Though, I managed to install the lib under Linux without any problem. So, I still wonder what’s going on.
What if the module is building itself? I am using Python 3.11 on Windows 11 ARM (ARM may be relevant?) with the MSVC 14.1 build tools installed. I get the following error installed tree-sitter 0.21, and am trying to fix it (googling has led me to this thread.) The tree-sitter module is building as part of installation, which is why I don’t think the “compiled for a different version of Python” applies.
I used to have Python 3.12 on this machine, but had to go back to 3.11 because tree-sitter 0.21 requires <3.12. It did not show any installed modules left over from 3.12 via pip list, but I cleared to be sure via pip cache purge. So think this is a ‘clean’ version of Python 3.11 and there’s nothing from another version to confuse the linker.
Creating library build\temp.win32-cpython-311\Release\tree_sitter\_binding.cp311-win_arm64.lib and object build\temp.win32-cpython-311\Release\tree_sitter\_binding.cp311-win_arm64.exp
binding.obj : error LNK2001: unresolved external symbol __imp___PyArg_Parse_SizeT
binding.obj : error LNK2001: unresolved external symbol __imp__PyDict_SetDefault
binding.obj : error LNK2001: unresolved external symbol __imp__PyBool_FromLong
binding.obj : error LNK2001: unresolved external symbol __imp___PyObject_CallFunction_SizeT
binding.obj : error LNK2001: unresolved external symbol __imp__PyImport_ImportModule
binding.obj : error LNK2001: unresolved external symbol __imp__PyBytes_AsString
binding.obj : error LNK2001: unresolved external symbol __imp__PyBytes_FromObject
binding.obj : error LNK2001: unresolved external symbol __imp__PyExc_RuntimeError
binding.obj : error LNK2001: unresolved external symbol __imp__PyLong_FromLong
binding.obj : error LNK2001: unresolved external symbol __imp__PyErr_SetNone
binding.obj : error LNK2001: unresolved external symbol __imp__PyExc_MemoryError
binding.obj : error LNK2001: unresolved external symbol __imp__PyBytes_FromString
binding.obj : error LNK2001: unresolved external symbol __imp___Py_NoneStruct
binding.obj : error LNK2001: unresolved external symbol __imp__PyMemoryView_FromObject
binding.obj : error LNK2001: unresolved external symbol __imp__PyList_Size
binding.obj : error LNK2001: unresolved external symbol __imp__PyErr_SetString
binding.obj : error LNK2001: unresolved external symbol __imp__PyExc_ValueError
binding.obj : error LNK2001: unresolved external symbol __imp__PyLong_FromUnsignedLong
binding.obj : error LNK2001: unresolved external symbol __imp___PyArg_ParseTupleAndKeywords_SizeT
binding.obj : error LNK2001: unresolved external symbol __imp__PyErr_Format
binding.obj : error LNK2001: unresolved external symbol __imp__PyTuple_Type
binding.obj : error LNK2001: unresolved external symbol __imp___Py_FalseStruct
binding.obj : error LNK2001: unresolved external symbol __imp___Py_Dealloc
binding.obj : error LNK2001: unresolved external symbol __imp__PyTuple_GetItem
binding.obj : error LNK2001: unresolved external symbol __imp__PyModule_AddObjectRef
binding.obj : error LNK2001: unresolved external symbol __imp___PyArg_ParseTuple_SizeT
binding.obj : error LNK2001: unresolved external symbol __imp__PyUnicode_FromFormat
binding.obj : error LNK2001: unresolved external symbol __imp__PyObject_GetBuffer
binding.obj : error LNK2001: unresolved external symbol __imp__PyList_New
binding.obj : error LNK2001: unresolved external symbol __imp__PyModule_Create2
binding.obj : error LNK2001: unresolved external symbol __imp__PySlice_New
binding.obj : error LNK2001: unresolved external symbol __imp__PyExc_SyntaxError
binding.obj : error LNK2001: unresolved external symbol __imp__PyObject_GetAttrString
binding.obj : error LNK2001: unresolved external symbol __imp___PyObject_CallMethod_SizeT
binding.obj : error LNK2001: unresolved external symbol __imp__PyErr_Clear
binding.obj : error LNK2001: unresolved external symbol __imp__PyList_Append
binding.obj : error LNK2001: unresolved external symbol __imp__PyObject_RichCompareBool
binding.obj : error LNK2001: unresolved external symbol __imp__PyTuple_Size
binding.obj : error LNK2001: unresolved external symbol __imp__PyType_GetModuleState
binding.obj : error LNK2001: unresolved external symbol __imp___Py_HashPointer
binding.obj : error LNK2001: unresolved external symbol __imp__PyBytes_Size
binding.obj : error LNK2001: unresolved external symbol __imp__PyDict_SetItem
binding.obj : error LNK2001: unresolved external symbol __imp__PyDict_New
binding.obj : error LNK2001: unresolved external symbol __imp__PyList_GetItem
binding.obj : error LNK2001: unresolved external symbol __imp__PyObject_IsInstance
binding.obj : error LNK2001: unresolved external symbol __imp__PyLong_FromVoidPtr
binding.obj : error LNK2001: unresolved external symbol __imp__PyExc_StopIteration
binding.obj : error LNK2001: unresolved external symbol __imp__PyLong_AsVoidPtr
binding.obj : error LNK2001: unresolved external symbol __imp__PyObject_GetItem
binding.obj : error LNK2001: unresolved external symbol __imp__PyExc_TypeError
binding.obj : error LNK2001: unresolved external symbol __imp__PyType_FromModuleAndSpec
binding.obj : error LNK2001: unresolved external symbol __imp__PyExc_NameError
binding.obj : error LNK2001: unresolved external symbol __imp__PyTuple_Pack
binding.obj : error LNK2001: unresolved external symbol __imp__PyCallable_Check
binding.obj : error LNK2001: unresolved external symbol __imp__PyModule_GetState
binding.obj : error LNK2001: unresolved external symbol __imp__PyList_SetItem
binding.obj : error LNK2001: unresolved external symbol __imp__PyUnicode_FromString
binding.obj : error LNK2001: unresolved external symbol __imp__PyLong_FromSize_t
binding.obj : error LNK2001: unresolved external symbol __imp__PyBuffer_Release
binding.obj : error LNK2001: unresolved external symbol __imp__PyObject_Call
binding.obj : error LNK2001: unresolved external symbol __imp__PyUnicode_FromStringAndSize
build\lib.win32-cpython-311\tree_sitter\_binding.cp311-win_arm64.pyd : fatal error LNK1120: 61 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.41.34120\\bin\\HostX86\\x86\\link.exe' failed with exit code 1120