"#! /usr/bin/env python" does not work..... help

Hi folks.

I've left this post on devshed as well but I can't get an answer and I'm real stuck.

I am trying to learn Python and I've done quite a bit in the last three weeks in the IDLE environment. However I am now trying to get my programs to execute from the command line in Fedora Linux using [italic]#! /usr/bin/env python[/italic] but I just can't get it to work.

I have [italic]env[/italic] and [italic]python[/italic] in the /usr/bin directory. I have changed the permissions using [italic]chmod +x[/italic] for my file and whenever I try to execute without the [italic]python[/italic] command Bash just reports command not found:

[b][root@localhost moonshinerat]# mycode.py
bash: mycode.py: command not found
[root@localhost moonshinerat]# mycode
bash: mycode: command not found
[root@localhost moonshinerat]#[/b]

I'm at my wits end with this and I'm going to defect to Ruby if I can't get this simple thing to work. Thanks for any solutions guys,



  • Hi,

    1) Does just #!/usr/bin/python work?

    2) Does ./mycode.py work? If so, then to get it to work the way you want, you must put the current working directory in your path, or the directory where the script is.

    3) Make sure mycode.py is chmod executable.

    4) Your problem is language independent. But if you're going to defect, at least defect to Perl! We have some awesome conferences, with lots of beer drinking on the evenings. :-)

    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
  • step 1:
    execute pwd command
    step 2:
    PATH=$PATH:output of pwd command
    i.e add the current path to PATH environment variable then ony you can do it else ./filename.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!