I write a lot of short utility python scripts that eventually make their way to people that are not computer literate and it ends up being quite challenging to get them to install python with the correct modules. I do not want to use something like py2exe because they just repackages the interpreter and can run slower (speed is a major concern on some of these scripts). I know interpretive languages like Matlab offer the ability to translate their scripts into a binary executable for speed and portability and I am hopeful to do the same with python. Also please note that I am an expert Fortran 77 to 2008 programmer, but terrible at C/C++.
I have read that it is possible to compile python code with cython and the --embed option. The problem I am having is I have found only references on how to do the final compilation with GCC and for unix or they refer to broken .../embedcython links. I do have a copy of visual studio 2008, but unsure how to set up a project in order to compile a static executable from cython code. This executable needs to be independent of the python interpreter and portable to someone without it installed. Typically these programs are written in Fortran, but I prefer python because of its easy of code, good OS and IO support, and flexibility compared to Fortran under certain circumstances.
I have been able to run Cython with --embed and deduced the following compile options:
set FILE_X=MyScript
set INC=C:\Python27\include
set INC2=C:\Python27\PC
set PYLIB=C:\Python27\libs
set PYLIB2=C:\Python27\PCbuild
cython %FILE_X%.pyx --embed
CL.exe /c /nologo /Ox /MT /W3 /GS- /DNDEBUG /I%INC% /I%INC2% /Fo%FILE_X%.obj /Tc%FILE_X%.c
LINK.exe /OUT:%FILE_X%.exe /nologo /INCREMENTAL:NO /LIBPATH:%PYLIB% /LIBPATH:%PYLIB2% %FILE_X%.obj /MANIFESTFILE:%FILE_X%.manifest
The problem I have with this is Symantic Endpoint Protection immediately locks the file and quarantines it as a virus. If I remove the quarantine, then it immediately re-quarantines it. Normally I would not care, but this software will be used on government computers, which will have this same software, thus preventing my end-users from running the compiled code. This also leaves me with the inability to test if the code even works.
Any comments on how to compile a windows, stand alone, executable/binary based on python code would be greatly appreciated. Please note that a lot of the previous stackoverflow answers refer to links that are dead.
I do have visual studio 2008, so if there are suggestion on how to create a project for compiling the cython c code in a project is greatly appreciated (I have other versions too, but I assume that is the only one that works for cython code?). In that case I just would have the project solution point to the generated c-file and compile it within Visual Studio. Also any edits to my compile batch script would be greatly appreciated.
In summary would I'd like is a way to take
MyScipt.pyx use cython to make MyScript.c, then statically compile it to MyScript.exe
and give that executable to someone without the python interpreter, but they can run it by either double clicking on it or typing it in the command prompt.
Thanks