Getting Python scripts to execute in RedHat

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pythor

    #1

    Getting Python scripts to execute in RedHat

    I apologise if this is a stupid newbie error, but I've been googling
    "hash bang" and "shebang" all morning. I've added the shebang to my
    scripts:

    #!/usr/bin/python

    I've added execute permissions:

    chmod +rx shebang.py

    But I still can't execute my scripts by themselves

    shebang.py ## produces error

    python shebang.py ## runs correctly

    I found one site that mentioned adding "./" to the beginning, and that
    works.

    ../shebang.py ## runs correctly.

    I gather that there's a path problem then. My script is in
    ~/pyscripts/. How do I get my scripts to run without using "./"?

  • Daniel Nogradi

    #2
    Re: Getting Python scripts to execute in RedHat

    > I apologise if this is a stupid newbie error, but I've been googling[color=blue]
    > "hash bang" and "shebang" all morning. I've added the shebang to my
    > scripts:
    >
    > #!/usr/bin/python
    >
    > I've added execute permissions:
    >
    > chmod +rx shebang.py
    >
    > But I still can't execute my scripts by themselves
    >
    > shebang.py ## produces error
    >
    > python shebang.py ## runs correctly
    >
    > I found one site that mentioned adding "./" to the beginning, and that
    > works.
    >
    > ./shebang.py ## runs correctly.
    >
    > I gather that there's a path problem then. My script is in
    > ~/pyscripts/. How do I get my scripts to run without using "./"?[/color]

    Add ~/pyscripts to your path for example by putting this into your
    ..bash_profile if you are using bash:

    PATH=$PATH:$HOM E/pyscripts
    export PATH

    HTH,
    Daniel

    Comment

    • Pythor

      #3
      Re: Getting Python scripts to execute in RedHat


      Dennis Lee Bieber wrote:[color=blue]
      > Now, if you mean you store all your python programs in
      > "~/pyscripts/" but you want them to run from any directory, you need to
      > add "~/pyscripts/" to your login PATH definition. If you want to always
      > make the local directory valid, add the "./".[/color]


      Thank You. Between your explanation and the previous poster's
      instruction, I've got it.

      Comment

      Working...