windows executable calling python script

Andrea Crotti andrea.crotti.0 at
Mon Feb 27 15:21:31 CET 2012

On 02/27/2012 01:57 PM, Andrea Crotti wrote:
> I am creating an installer for python projects, using CMake and NSIS.
> Now my goal is to be able to select at installer time the python 
> executable that will run that project,
> and then associate them.
> I saw that setuptools is able to generate exe wrappers, but how does 
> that work exactly?
> From what I've understood there is some compiled C code that somehow 
> calls the python script, is that correct?
> Supposing I ship this executable in the same directory of the python 
> script (with a known name), is there a way
> to make it run the right python interpreter?
> The best and easiest solution would be to generate the full installer 
> with PyInstaller or similar, but unfortunately
> that doesn't work yet, and we would still need both approaches anyway.

At the moment I ended up with something like this:

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

// the function takes as arguments only the python interpreter full path
int main(int argc, char *argv[])
   if (argc < 2) {
     fprintf(stderr, "Usage = ./run <python_executable_path>");
   /* TODO: make the path absolute? is it necessary? */
   char *const to_run[1] = {""};
   /* TODO: check if the path exists or not, and if it's executable */

   execv(argv[1], to_run);
   return 1;

which still doesn't work (I have to fix the execv) but when it will in 
theory I will only need
to tell NSIS to create a link to that executable passing as argument the 
right python executable.
After that it will run the with in the local directory..

Easier ways (without py2exe and similars?)?

More information about the Python-list mailing list