[distutils] Install script under a different name

Discussion in 'Python' started by Nikolaus Rath, Dec 5, 2009.

  1. Hello,

    All my Python files have extension .py. However, I would like to install
    scripts that are meant to be called by the user without the suffix, i.e.
    the file scripts/doit.py should end up as /usr/bin/doit.

    Apparently the scripts= option of the setup() function does not support
    this directly. Is there a clever way to get what I want?


    Best,

    -Nikolaus

    --
    »Time flies like an arrow, fruit flies like a Banana.«

    PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
    Nikolaus Rath, Dec 5, 2009
    #1
    1. Advertising

  2. Nikolaus Rath

    Lie Ryan Guest

    On 12/5/2009 11:34 AM, Nikolaus Rath wrote:
    > Hello,
    >
    > All my Python files have extension .py. However, I would like to install
    > scripts that are meant to be called by the user without the suffix, i.e.
    > the file scripts/doit.py should end up as /usr/bin/doit.
    >
    > Apparently the scripts= option of the setup() function does not support
    > this directly. Is there a clever way to get what I want?


    if this is on windows, you should add ".py" to the PATHEXT environment
    variable.

    on linux/unix, you need to add the proper #! line to the top of any
    executable scripts and of course set the executable bit permission
    (chmod +x scriptname). In linux/unix there is no need to have the .py
    extension for a file to be recognized as python script (i.e. just remove
    it).
    Lie Ryan, Dec 5, 2009
    #2
    1. Advertising

  3. Re: Install script under a different name

    On Dec 5, 1:52 am, Lie Ryan <> wrote:
    > on linux/unix, you need to add the proper #! line to the top of any
    > executable scripts and of course set the executable bit permission
    > (chmod +x scriptname). In linux/unix there is no need to have the .py
    > extension for a file to be recognized as python script (i.e. just remove
    > it).


    The #! line will even get replaced by the interpreter used during
    installation, so you can safely write "#!/usr/bin/env python" in your
    development copy and get "#!/usr/bin/python" when users install it.
    Floris Bruynooghe, Dec 5, 2009
    #3
  4. On Fri, Dec 04, 2009 at 19:34 -0500, Nikolaus Rath wrote:
    > All my Python files have extension .py. However, I would like to install
    > scripts that are meant to be called by the user without the suffix, i.e.
    > the file scripts/doit.py should end up as /usr/bin/doit.


    > Apparently the scripts= option of the setup() function does not support
    > this directly. Is there a clever way to get what I want?


    Just name the file you want to install 'doit' and not 'doit.py'. That
    would be the easiest way. You might run into problems on Windows though,
    which IIRC (it's been a while) heavily relies on file suffixes and not
    on their content. That might have changed in the last 10 years though,
    so better check that first.

    You can also use entry points to create the executable at install time.
    Have a look at [1] which explains how this is done. This requires using
    Distribute/setuptools though, ...

    [1] http://packages.python.org/distribute/setuptools.html#automatic-script-creation
    --
    .''`. Wolodja Wentland <-heidelberg.de>
    : :' :
    `. `'` 4096R/CAF14EFC
    `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.10 (GNU/Linux)

    iQIcBAEBCAAGBQJLGkYEAAoJEIt/fTDK8U781q4P/3oK/RZ3ncDUmYVFRXFlF5tv
    5heq94i7BLoo6U5Lw6P0E/+oMxC7TeWtmzvsF7eRY4j31MbO5SU4J+nnN+3bHplT
    tbBb7yHdE6bxBBpOg2recVcJAhYDP4bj1/VKsNq4mScNZaOF+uh8ZmxkQaas+b13
    NVhLnGGV8fu3cI77nYfrHgd10tuQdeR7/TAMLGyI3zH0+f9XLy9nuB/XnCvnWIEo
    2tfnkO+1816L1URHjJ50E69BGp56ONRk4wvsIeXOtqIAY7Fv+xBtZQHvVp+NWZVX
    7j6+0+XXIqf52NsVC+M5GOdx9nD5IefrX5kV3E/MnQgD6dxu52JH4RnuAxRB6OdL
    /WgCNjikCR1kXA05u3TlcFFXIlTdhtqZaxahdLQzCxwe1cwsgZBVPY7TF/AdNvDS
    MtmG4G5CE0SgNO6cBldug4i9Z5LPvwY+Q2RZteeGbXHThXZAwanBouvfUFH2kgkX
    dIBcZrHbBb5DKQfQYoUSLa8gXpP5TphUMAf9Xvw2dLqUugjY5BGrLaf3sz0uNPW0
    5e+EntO4HK+n17g5iJjquVA/3uyDp+AuLtCJKl5vaCpN2avBpl/kCwFGEtlxfvEo
    sYIZQlEgzR5OPeSIIgay2lMjmRvoDPV6yBjU2DwETfyglPcNKoEpMkD7sVdVBl4p
    mpTAuHdQNCruR3VBj8rJ
    =27c+
    -----END PGP SIGNATURE-----
    Wolodja Wentland, Dec 5, 2009
    #4
  5. Lie Ryan <> writes:
    > On 12/5/2009 11:34 AM, Nikolaus Rath wrote:
    >> Hello,
    >>
    >> All my Python files have extension .py. However, I would like to install
    >> scripts that are meant to be called by the user without the suffix, i.e.
    >> the file scripts/doit.py should end up as /usr/bin/doit.
    >>
    >> Apparently the scripts= option of the setup() function does not support
    >> this directly. Is there a clever way to get what I want?

    >
    > if this is on windows, you should add ".py" to the PATHEXT environment
    > variable.
    >
    > on linux/unix, you need to add the proper #! line to the top of any
    > executable scripts and of course set the executable bit permission
    > (chmod +x scriptname). In linux/unix there is no need to have the .py
    > extension for a file to be recognized as python script (i.e. just
    > remove it).


    Sorry, but I think this is totally unrelated to my question. I want to
    rename files during the setup process. This is not going to happen by
    adding/changing any #! lines or the permissions of the file.

    I know that there is no need to have the .py extension, that's why I
    want to install the scripts without this suffix. But in my source
    distribution I want to keep the suffix for various reasons.

    Best,

    -Nikolaus

    --
    »Time flies like an arrow, fruit flies like a Banana.«

    PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
    Nikolaus Rath, Dec 5, 2009
    #5
  6. Wolodja Wentland <-heidelberg.de> writes:
    > On Fri, Dec 04, 2009 at 19:34 -0500, Nikolaus Rath wrote:
    >> All my Python files have extension .py. However, I would like to install
    >> scripts that are meant to be called by the user without the suffix, i.e.
    >> the file scripts/doit.py should end up as /usr/bin/doit.

    >
    >> Apparently the scripts= option of the setup() function does not support
    >> this directly. Is there a clever way to get what I want?

    >
    > You can also use entry points to create the executable at install time.
    > Have a look at [1] which explains how this is done. This requires using
    > Distribute/setuptools though, ...
    >
    > [1] http://packages.python.org/distribute/setuptools.html#automatic-script-creation


    That looks perfect, thanks!


    Best,

    -Nikolaus

    --
    »Time flies like an arrow, fruit flies like a Banana.«

    PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
    Nikolaus Rath, Dec 5, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Qiangning Hong
    Replies:
    1
    Views:
    532
    F. Petitjean
    Apr 17, 2005
  2. timw.google
    Replies:
    1
    Views:
    519
    Serge Orlov
    May 11, 2006
  3. Replies:
    0
    Views:
    304
  4. Luis Alberto Zarrabeitia Gomez

    distutils, No module named numpy.distutils.fcompiler.conv_template

    Luis Alberto Zarrabeitia Gomez, Mar 30, 2009, in forum: Python
    Replies:
    0
    Views:
    1,288
    Luis Alberto Zarrabeitia Gomez
    Mar 30, 2009
  5. j vickroy
    Replies:
    5
    Views:
    1,806
    j vickroy
    Nov 6, 2009
Loading...

Share This Page