[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Installing a python script in $PREFIX/bin

From: Stefano Lattarini
Subject: Re: Installing a python script in $PREFIX/bin
Date: Mon, 29 Aug 2011 21:58:07 +0200
User-agent: KMail/1.13.7 (Linux/2.6.30-2-686; KDE/4.6.5; i686; ; )

On Monday 29 August 2011, Neal H wrote:
> I'm a bit confused about how to build/install a Python script.
Let's first see the bits about python modules ...

> I build and install Python modules by placing the following in my
> my file:
>   AM_PATH_PYTHON([2.4])
> and the following in a file:
>   python_PYTHON =
This is good.

> This correctly detects python and installs the source and compiled
> modules (.pyo and .pyc) in the right place (i.e.,
> $PREFIX/lib/python-VERSION/site-packages/).
Just as an aside, notice that python version from 3.2 onwards have
changed the place where they look for pre-compiled modules, so they
won't consider nor use the Automake-installed .pyo and .pyc files
(there is an open bug report in the automake tracker about this).
This won't prevent your installed package from working, but it will
add some run-time overhead, since the .py files will have to be
recompiled on-the-fly each time.

> I also have a script that uses these modules,  I want this
> to be installed in /usr/bin as 'script'.  I'd preferably like a
> compiled version of the script to be installed there.
> I'd also like to install the sources.  What should I do?
> I see three options:
> - Build 'script' from, i.e., copy and mark it as
>   executable.  Add 'script' to dist_bin_SCRIPTS.  This has the
>   disadvantage that the executable is not compiled (and thus has a
>   slightly longer start up time).
I'd go with this, the extra startup time is mostly so low that it's
not really worth worrying about.  But if you really want to squeeze
out all the possibile from it, my suggestion would be to put all the
real code of your package in modules, and have your script be just a
thin layer around them, ideally something like:

  #!/usr/bin/env python
  from my.wonderful.package import main

(BTW, to be 100% correct, you might want to use the python interpreter
determined at configure time in the shebang line of your script).

> - Create a symbolic link from $PREFIX/bin/script to
>   $PREFIX/lib/python-VERSION/site-packages/script.pyo and make the
>   compiled version executable using automake's install-exec target.
But then, how do you expect your system to run that script with the
correct interpreter?  More importantly, how do you expect your
users' systems to?

> - Create a simple shell script that does something along the lines of
>   'exec @PYTHON@ $PREFIX/lib/python-VERSION/site-packages/script.pyo"$@"'.
>   Like the first option, this has some overhead.
This is also a viable option (even if the extra fork involved might slow
things down on Cygwin a little too much).  Still, if you go for it, you
should really use the site-package directory determined at configure time:

  exec @PYTHON@ '@pythondir@/script.pyo' ${1+"$@"}

> Suggestions?
> Thanks,
> Neal

reply via email to

[Prev in Thread] Current Thread [Next in Thread]