[Tutor] python scripting using "./"

Walter Prins wprins at gmail.com
Tue May 24 15:27:38 CEST 2011


The problem likely is as intimated by the error message that your python
interpreter not called "/usr/local/bin/python3.1" but I'd offhand guess,
probably "/usr/local/bin/python".  (Indeed, you run the interpreter yourself
as "python" not "python3.1" so you should not be using "python3.1" in your
script header.)

To check, try:

John-Wilkinsons-iMac:~ wilkinson$ which python

Assuming you have the "which" command this will tell you which version of
python is used then you do e.g. "python hello.py."  Then change the
hash-bang (#!) header in your script to match the location you found.  (If
you dont have "which", you can also try "whereis" or "env" or "type -a".)

Note, some people use the following hash-bang header in preference of a hard
coded path as I've suggested above, as follows:

#!/usr/bin/env python

/usr/bin/env goes off and looks up the appropriate path for (in this case)
the "python" interpreter, then passes control to that, thereby making your
script a little less dependent on a hardcoded paths present on your system.
This works provided of course that "env" is available and found in
/usr/bin.  (Thought I'd mention that in case you wanted to use that
instead/try it.)

Disclaimer: I don't have a Mac, the above is basically general advice which
should however work any Unix'ish or GNU'ish system, including I believe on
the Mac providing Apple's not changed things that I'm not aware of.

Hope that helps

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110524/ac3aefc3/attachment.html>


More information about the Tutor mailing list