1

I have some algorythms that are implemented in Python but I need to make them portable to access them with Java JNI or directly from C. They don't have scary dependencies but they are updated on a release schedule so reimplementation is not an option. Jython has let me down because the algorythms are in Python 3. I'm trying to use Cython, which looks promising on Windows 10. I have read about on other threads and I have Visual Studio Build Tools for 16.11 (1929) which is the version my Python is also compiled with per this question.

from setuptools import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("C:\\Users\\stephen\\pyp\\VS.pyx")
)

and I invoke this with

python setup.py build_ext --inplace --compiler=msvc

It seems to compile but fails at the linker step:

(pyp) C:\Users\stephen\pyp>python setup.py build_ext --inplace
running build_ext
building 'VS' extension
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\stephen\pyp\include -IC:\Users\stephen\AppData\Local\Programs\Python\Python310\include -IC:\Users\stephen\AppData\Local\Programs\Python\Python310\Include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt -IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt /TcC:\Users\stephen\pyp\VS.c /Fobuild\temp.win32-3.10\Release\Users\stephen\pyp\VS.obj
VS.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\stephen\pyp\libs /LIBPATH:C:\Users\stephen\AppData\Local\Programs\Python\Python310\libs /LIBPATH:C:\Users\stephen\AppData\Local\Programs\Python\Python310 /LIBPATH:C:\Users\stephen\pyp\PCbuild\win32 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\lib\x86 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x86 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x86 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\lib\x86 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x86 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x86 /EXPORT:PyInit_VS build\temp.win32-3.10\Release\Users\stephen\pyp\VS.obj /OUT:build\lib.win32-3.10\VS.cp310-win_amd64.pyd /IMPLIB:build\temp.win32-3.10\Release\Users\stephen\pyp\VS.cp310-win_amd64.lib
   Creating library build\temp.win32-3.10\Release\Users\stephen\pyp\VS.cp310-win_amd64.lib and object build\temp.win32-3.10\Release\Users\stephen\pyp\VS.cp310-win_amd64.exp
VS.obj : error LNK2001: unresolved external symbol __imp__PyBaseObject_Type
VS.obj : error LNK2001: unresolved external symbol __imp__PyObject_SetAttr
VS.obj : error LNK2001: unresolved external symbol __imp__PyUnicode_InternFromString
VS.obj : error LNK2001: unresolved external symbol __imp__PyCFunction_Type
VS.obj : error LNK2001: unresolved external symbol __imp__PyOS_snprintf
VS.obj : error LNK2001: unresolved external symbol __imp__PyThreadState_Get
VS.obj : error LNK2001: unresolved external symbol __imp__PyExc_Exception
<...>
VS.obj : error LNK2001: unresolved external symbol __imp___Py_TrueStruct
VS.obj : error LNK2001: unresolved external symbol __imp__PyExc_SystemError
VS.obj : error LNK2001: unresolved external symbol __imp__PyObject_Call
VS.obj : error LNK2001: unresolved external symbol __imp__PyUnicode_FromStringAndSize
VS.obj : error LNK2001: unresolved external symbol __imp___PyObject_GetDictPtr
build\lib.win32-3.10\VS.cp310-win_amd64.pyd : fatal error LNK1120: 64 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x86\\link.exe' failed with exit code 1120

Seems there's a library missing here that contains Python symbols but my knowledge of the windows software ecosystem is letting me down, any help appreciated.

spl
  • 510
  • 4
  • 15
  • 1
    have you found a solution to this? your input is appreciated! @spl – sos Sep 30 '22 at 05:00
  • @sos No not really. I think you would have to exactly match the libraries in Visual Studio with the versions that were used to compile the installed Python. Even then I made a valiant effort to do just that but the Windows software ecosystem bested me and I retreated to UNIX. I am much more optimistic at achieving this portability in Graal VM, and have achieved some early success there. – spl Sep 30 '22 at 14:45

0 Answers0