Results 1 to 6 of 6

Thread: Python script in /usr/local/bin won't run

  1. #1
    Join Date
    Jul 2010
    Beans
    12
    Distro
    Ubuntu Studio 10.04 Lucid Lynx

    Python script in /usr/local/bin won't run

    Hi folks!

    I am running Ubuntu 10.04 Lucid.

    I recently wrote a script (hello.py) in Python and placed it in /usr/local/bin. The first line of the program is
    Code:
    #!/usr/bin/python
    and I double-checked that it is marked as executable. Furthermore, I double checked that the newline character after the first line of the program was "\n" rather than "\r\n". If I use the commands "./hello.py" or "python hello.py" while in the /usr/local/bin directory, the script successfully executes, but if I move to an arbitrary directory and try either of these commands, I get "Command not found" and "No such file or directory" respectively.

    Running "ls -l" in /usr/local/bin returns the following results:
    -rwxr-xr-x 1 root root 40 2010-07-06 15:00 hello.py

    I have also double-checked that /usr/local/bin is listed when I run the command "echo $PATH".

    Any ideas on why this isn't working? Need any further information to help with diagnosis? Thanks!

  2. #2
    Join Date
    Jul 2009
    Location
    Baltimore/Pittsburgh
    Beans
    70
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Python script in /usr/local/bin won't run

    When you are in an arbitrary directory, you can just type "hello.py" (rather than "./hello.py" and it should work. It should even tab-complete for you.

  3. #3
    Join Date
    Apr 2010
    Location
    England
    Beans
    3,286

    Re: Python script in /usr/local/bin won't run

    If it's not exectuing, then perhaps /usr/local/bin isn't in your PATH variable. Post the output of 'echo $PATH' here.

    EDIT: Clearly I didn't read your original post very well.
    Last edited by WorMzy; July 6th, 2010 at 08:54 PM.
    http://xkcd.com/293/
    There are 10 kinds of people in this world: Those who understand ternary, those who don't, and those who confuse it with binary.

  4. #4
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Python script in /usr/local/bin won't run

    Hi, and just to explain further:
    Code:
    ./hello.py
    means execute hello.py in the current directory.
    Code:
    python hello.py
    means run python, and have it execute hello.py in the current directory
    Code:
    hello.py
    means search PATH and execute the first occurrence it finds of hello.py in one of the PATH directories.

  5. #5
    Join Date
    Jan 2009
    Location
    MA
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Python script in /usr/local/bin won't run

    The "." in "./hello.py" is for current directory. Hence it doesn't work outside /usr/local/bin.
    The DRUNKS - For Your Inner Drunk

  6. #6
    Join Date
    Jul 2010
    Beans
    12
    Distro
    Ubuntu Studio 10.04 Lucid Lynx

    Re: Python script in /usr/local/bin won't run

    Thanks so much ladies and gents! That clears it up perfectly. In retrospect, a rather stupid mistake...

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •