3

How do I 'install' a python script so I can run it when ever I want?

My script looks like:

#/usr/bin/env python
import os;

while True:
    comm = input();
    os.system(comm);

But when i try to run it I get:

/usr/bin/doors.py line2: command not found 
...

How to I fix this?

Vid
  • 41

1 Answers1

4

You have a typo in shebang line, which specifies interpreter to use. It should be:

#!/usr/bin/env python

which will default to python2.7. Since you've tagged your question python3, you may want to use:

#!/usr/bin/env python3

You should use the #!/usr/bin/env python3 line .

As it stands now, your shell is interpreting the script with shebang being treated as a comment as it starts with #. Thus, there's no interpreter specified, and by default script will be executed with your current shell. The shell has no idea of what import is , hence the command not found error is being shown by the shell.

As a side note, for running native shell commands in python, use the subprocess module instead of unsecured and deprecated os.system function.

Also why are you running user input blindly without any sanity checking?

muru
  • 197,895
  • 55
  • 485
  • 740
heemayl
  • 91,753