Launching Python programs from Linux shell script

Discussion in 'Python' started by Ernesto, Sep 9, 2005.

  1. Ernesto

    Ernesto Guest

    Does anyone know how to start Python program(s) from a Linux shell
    script? Is it just

    $python myscript.py

    ??

    Thanks,
    Ernesto, Sep 9, 2005
    #1
    1. Advertising

  2. Ernesto

    tooper Guest

    Yes, provided your python interpreter is installed, and in your path
    ("$ whereis python" should give you something like /usr/bin/python or
    /usr/local/bin/python)
    tooper, Sep 9, 2005
    #2
    1. Advertising

  3. Ernesto

    tooper Guest

    Yes, provided your python interpreter is installed, and in your path
    ("$ whereis python" should give you something like /usr/bin/python or
    /usr/local/bin/python)
    tooper, Sep 9, 2005
    #3
  4. Yes...
    -------------------------------------------------
    Or...
    Add this line in de source:
    #!/usr/bin/env python
    then
    chmod +x myscript.py
    ../myscript.py


    On 9 Sep 2005 08:31:27 -0700, Ernesto <> wrote:
    > Does anyone know how to start Python program(s) from a Linux shell
    > script? Is it just
    >
    > $python myscript.py
    >
    > ??
    >
    > Thanks,
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Ruben Charles, Sep 9, 2005
    #4
  5. Ernesto

    Ernesto Guest

    Thanks! How do you add Python in Linux to the path? Similar to
    setting environment variables in Windows. I want to be able to type
    "python" when I'm in any directory to launch the interpreter. Thanks!
    Ernesto, Sep 12, 2005
    #5
  6. Ernesto

    Steve Holden Guest

    Ernesto wrote:
    > Thanks! How do you add Python in Linux to the path? Similar to
    > setting environment variables in Windows. I want to be able to type
    > "python" when I'm in any directory to launch the interpreter. Thanks!
    >

    You will (or should) have a shell intialisation file variously called
    ..profile, .bashrc or several other possible names. Consult your shell
    documentation (or ask another user who knows) to find out which.

    You will need to add a line which typically reads something like

    export PATH=$PATH:/path/to/directory/containing/python

    making the obvious substitution of the correct path. Interestingly I
    couldn't quickly formulate a Google search specifically containing
    Python, but a search for

    unix add to path

    gives the quite helpful

    http://www.ee.surrey.ac.uk/Teaching/Unix/unix8.html

    as its first result.

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
    Steve Holden, Sep 12, 2005
    #6
  7. Ernesto

    Magnus Lycka Guest

    Ernesto wrote:
    > Thanks! How do you add Python in Linux to the path?


    This works out of the box in most modern Linux distributions.

    If you're open to suggestions, I'd suggest that you have a
    look at Ubuntu. It's a user friendly Linux distribution with
    rather close ties to the Python community.

    Anyway, if Python is installed in a non-standard location on
    your machine, you might need to set up two things:

    PATH to the directory containing the python binary.
    PYTHONPATH to the directories containing Python modules and
    packages.

    How to do this has nothing to do with Python, it just depends
    on what shell(s) you use in Linux, and this is frankly not the
    forum for that.

    See e.g. http://docs.python.org/tut/node4.html and
    http://www.python.org/doc/tut/node8.html for more about PATH
    and PYTHONPATH--actually, it might be a good idea to read the
    whole tutorial if you're a beginner.
    Magnus Lycka, Sep 13, 2005
    #7
    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. Gros Bedo
    Replies:
    2
    Views:
    1,280
    Piet van Oostrum
    Jul 10, 2008
  2. Gros Bedo
    Replies:
    1
    Views:
    652
    Piet van Oostrum
    Jul 10, 2008
  3. norseman
    Replies:
    0
    Views:
    553
    norseman
    Jul 10, 2008
  4. Gros Bedo
    Replies:
    0
    Views:
    408
    Gros Bedo
    Jul 13, 2008
  5. moongeegee

    execute a shell script in a shell script

    moongeegee, Dec 3, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    240
    Ben Morrow
    Dec 4, 2007
Loading...

Share This Page