far wrote:
"#!/usr/bin/env python" works only if python is in your path. Otherwise you would use "#!/usr/bin/python" or whatever, but then you have to know the path to the Python interpreter. The env program can usually be assumed to be in /usr/bin, but it is by no means certain.
If you are doing a bigger project and using the python distutils, they will automatically substitute the "shebang" (as it's called) with the location of the python executable upon installation.
Hmmm. Ok. I guess I'm alittle confused then. I'm sure you can help clear this up though. Two things I don't quite understand fully is where's the best place to place my python scripts and should I be creating all my scripts as "root" or as a normal user? So far I've done everything as a normal user. (kind of thinking of security here but not really to worried about..just wondering)
This is what I see in "/usr/bin":
Code: Select all
/usr/bin/env and /usr/bin/python -> python2.3.
This is what I've done and would like to do. Please let me know if this is correct or what's correct if possible.
1) I would like to beable to have the ability to execute any of the python scripts that I create, by name, from any given directory so that I don't have to put the full complete path to the script in the terminal everytime I wana execute a python script as a normal user or as root.
2) Rightnow I've paritially fullfilled part of #1 above by giving my *.py scripts +x permissions and putting them in the "/usr/local/bin" directory. Right now they all start with "#!/usr/bin/python".
So from a terminal as a normal user and being in any given directory for example, I type "./junk.py" and it will execute. (not as root though) (thats easily fixed I just don't know whats proper. To have full root access or full user access or both?)
But from the same terminal session I cannot simply type in "python junk.py" without putting the full path to "junk.py" to execute the said script unless ofcourse I'm actually in the same directory.
So I would think that I would need to know the path that Python searches and then just adjust my user and root path to point to the same search path that Python looks in, put all my *.py scripts there, and all would be well.
The only other thing that I can think of is what's listed below but I'm unsure of which path below is correct and if any of what I'm explaining is correct or not.
Code: Select all
>>> import sys
>>> sys.path
['', '/usr/lib/python23.zip', '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload', '/usr/lib/python2.3/site-packages', '/usr/lib/portage/pym']
I'm sure I'll find most of the answers to my own questions throughout the day. Any opinions are appreciated though.
Thanks