3
$\begingroup$

Evidently, the mathlink Python extension has not been updated for some time. As shown below, it doesn't link to the correct libraries. Also, the API seems to have been updated while the mathlink source code has not.

:\Program Files\Wolfram Research\Mathematica\10.0\SystemFiles\Links\Python
>python setup.py build
running build
running build_ext
building 'mathlink' extension
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox
 /MD /W3 /GS- /DNDEBUG -DWINDOWS_MATHLINK "-IC:\Program Files\Wolfram Research\M
athematica\10.0\SystemFiles\Links\MathLink\DeveloperKit\Windows\CompilerAddition
s\mldev32\include" -Ic:\Python27\include -Ic:\Python27\PC /Tcmathlink.c /Fobuild
\temp.win32-2.7\Release\mathlink.obj
mathlink.c
mathlink.c(1473) : warning C4013: 'MLDisownByteString' undefined; assuming exter n returning int
mathlink.c(1555) : warning C4013: 'MLDisownString' undefined; assuming extern returning int
mathlink.c(1885) : warning C4013: 'MLDisownSymbol' undefined; assuming extern returning int
mathlink.c(2094) : warning C4013: 'MLDisownIntegerList' undefined; assuming extern returning int
mathlink.c(2167) : warning C4013: 'MLDisownRealList' undefined; assuming extern returning int
mathlink.c(2238) : warning C4013: 'MLDisownIntegerArray' undefined; assuming extern returning int
mathlink.c(2259) : warning C4013: 'MLDisownRealArray' undefined; assuming extern returning int
mathlink.c(3861) : warning C4047: 'function' : 'unsigned long' differs in levels of indirection from 'MLParametersPointer'
mathlink.c(3861) : warning C4024: 'MLNewParameters' : different types for formal and actual parameter 1
mathlink.c(3861) : warning C4020: 'MLNewParameters' : too many actual parameters 
mathlink.c(3861) : warning C4047: '=' : 'ulong_ct' differs in levels of indirect ion from 'MLEnvironmentParameter'
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\link.exe /DLL /nologo
 /INCREMENTAL:NO "/LIBPATH:C:\Program Files\Wolfram Research\Mathematica\10.0\Sy
stemFiles\Links\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\lib" /LI
BPATH:c:\Python27\libs /LIBPATH:c:\Python27\PCbuild ml32i3m.lib /EXPORT:initmath
link build\temp.win32-2.7\Release\mathlink.obj /OUT:build\lib.win32-2.7\mathlink
.pyd /IMPLIB:build\temp.win32-2.7\Release\mathlink.lib /MANIFESTFILE:build\temp.
win32-2.7\Release\mathlink.pyd.manifest Creating library build\temp.win32-2.7\Release\mathlink.lib and object build\temp.win32-2.7\Release\mathlink.exp
mathlink.obj : error LNK2019: unresolved external symbol _MLDisownByteString referenced in function _mathlink_GetLong
mathlink.obj : error LNK2019: unresolved external symbol _MLDisownString referenced in function _mathlink_GetString
mathlink.obj : error LNK2019: unresolved external symbol _MLDisownSymbol referenced in function _mathlink_GetSymbol
mathlink.obj : error LNK2019: unresolved external symbol _MLDisownIntegerList referenced in function _mathlink_GetIntegerList
mathlink.obj : error LNK2019: unresolved external symbol _MLDisownRealList referenced in function _mathlink_GetFloatList
mathlink.obj : error LNK2019: unresolved external symbol _MLDisownIntegerArray referenced in function _mathlink_GetIntArray
mathlink.obj : error LNK2019: unresolved external symbol _MLDisownRealArray referenced in function _mathlink_GetFloatArray
mathlink.obj : error LNK2019: unresolved external symbol _MLNewParameters@8 referenced in function _Env_Alloc
build\lib.win32-2.7\mathlink.pyd : fatal error LNK1120: 8 unresolved externals
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\link
.exe"' failed with exit status 1120
$\endgroup$

2 Answers 2

2
$\begingroup$

You also need to add the library path, not just the missing include directory.

It's easier to just edit the setup.py file. Here are my instructions, for 64-bit. Since you are using 32-bit, some modifications will be required:

* Edit "C:\Program Files\Mathematica\SystemFiles\Links\Python\setup.py"
    line 53: include_dirs = [r"C:\Program Files\Mathematica\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions\mldev64\include"],
    line 54: library_dirs = [r"C:\Program Files\Mathematica\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions\mldev64\lib"],
    line 56: libraries = ["ml64i3m"]

Unfortunately, even if I managed to build mathlink.pyd using the above instructions, it doesn't work for me (it crashes). Maybe you'll have better luck with the 32-bit version.

$\endgroup$
2
  • $\begingroup$ Yes, I already have this in my setup.py for the 32-bit version. The main problem is that the symbols are not present in the library because the interface has changed and nobody at Wolfram has rewritten the source file to accommodate the new libraries. $\endgroup$
    – reckoner
    Commented Feb 28, 2015 at 0:30
  • 1
    $\begingroup$ I've heard that they removed the Python link completely in 10.0.2, so... $\endgroup$
    – Meh
    Commented Feb 28, 2015 at 1:01
0
$\begingroup$

The Python link is no longer included with Mathematica 10.0.2 and later.

There is a discussion of this on Wolfram Community:

http://community.wolfram.com/groups/-/m/t/444441

$\endgroup$
2
  • $\begingroup$ I know this is not quite an answer but I thought it was important to (visibly) point this out for people who might be looking at this thread, searching for PythonLink in Mathematica 10 and not finding it. $\endgroup$
    – Szabolcs
    Commented Mar 13, 2016 at 16:44
  • $\begingroup$ Thanks. This means Mathematica is a lot less useful to me now. $\endgroup$
    – reckoner
    Commented Jun 12, 2016 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.