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

Howdy, Stranger!

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


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

moonshineratmoonshinerat Posts: 4Member
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,



  • JonathanJonathan Posts: 2,914Member

    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.");
  • utpalenduutpalendu Posts: 9Member
    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.