I try to create an executable using Cython with embedded Python (look here). I can find examples doing this on Linux, but not on Windows. The only Windows example I can find results in an executable that calls the python dll (here). But this is not what I am looking for. I want a standalone executable that does not call the python dll.
Below what I did:
First the program (hello.py):
print("hello")
I run Cython with the --embed option in an anaconda prompt:
cython hello.py --embed
This results in a c file with a main function (hello.c).
Then set the appropriate environment variables:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
Then compile and link this:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe" /nologo /Ox /MD /W3 /GS- /DNDEBUG -Ic:\Anaconda3_5.2.0\include -Ic:\Anaconda3_5.2.0\PC /Tchello.c /link /OUT:"test.exe" /SUBSYSTEM:CONSOLE /LIBPATH:C:\Anaconda3_5.2.0\libs /LIBPATH:C:\Anaconda3_5.2.0\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64"
This results in a small (19 KB) executable (test.exe).
To run this set the PYTHONPATH
set PYTHONPATH=C:\Anaconda3_5.2.0
and call the program
test.exe
This runs whitout any problems, but Python is not embedded as it calls python36.dll. I suppose the compiling and linking must be done differently, but I don't know how. Does anybody know how to create a windows executable that embeds the Python interpreter using Cython? Any help will be greatly appreciated.