How to execute python script from console without writing full path?
Solution 1:
Set executable permissions for python scripts by "chmod +x *"
Now you have two options:
- Add your scripts directory to PATH env variable, or
- Make symbolic links to your scripts one by one (or write another script to do the same) in
/usr/local/bin
directory.
Example:[mzed@node02 test]$ vim printme.py
Contents of file:
#!/usr/bin/python
print "This is cool!"
-
[mzed@node02 test]$ mv printme.py printme
[mzed@node02 test]$ chmod +x printme
[mzed@node02 ~]$ cd /usr/local/bin/
[mzed@node02 bin]$ sudo ln -s ~/test/printme .
[mzed@node02 bin]$ ls
deskzilla grails grails-debug printme startGrails
[mzed@node02 bin]$ cd
[mzed@node02 ~]$ printme
This is cool!
[mzed@node02 ~]$
I hope this will help you.
Solution 2:
Okay, maybe I'm just older school...
In /usr/bin add shell scripts with the #!/bin/bash header and no .sh extension. Then in those scripts just run python absolutepath.
Why I think it's better than the other answers:
Doesn't require chmod-ing your scripts to make them executable.
Doesn't require renaming your scripts.