Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20940 > unrolled thread

Re: windows executable calling python script

Started byAndrea Crotti <andrea.crotti.0@gmail.com>
First post2012-02-27 14:21 +0000
Last post2012-02-27 14:21 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: windows executable calling python script Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-27 14:21 +0000

#20940 — Re: windows executable calling python script

FromAndrea Crotti <andrea.crotti.0@gmail.com>
Date2012-02-27 14:21 +0000
SubjectRe: windows executable calling python script
Message-ID<mailman.199.1330352496.3037.python-list@python.org>
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>");
     exit(1);
   }
   /* TODO: make the path absolute? is it necessary? */
   char *const to_run[1] = {"run.py"};
   /* 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 run.py with in the local directory..

Easier ways (without py2exe and similars?)?

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web