[Tutor] python scripting using "./"
I am trying to do script in python using "./" Here is a session showing "bad interpreter: No such file or directory" Is this a python question/problem? Last login: Sat May 21 14:22:49 on ttys000 John-Wilkinsons-iMac:~ wilkinson$ cd /Users/wilkinson/Documents/py32/p31summerfield John-Wilkinsons-iMac:p31summerfield wilkinson$ pwd /Users/wilkinson/Documents/py32/p31summerfield John-Wilkinsons-iMac:p31summerfield wilkinson$ ls hello.py hello.py John-Wilkinsons-iMac:p31summerfield wilkinson$ python hello.py Hello World! John-Wilkinsons-iMac:p31summerfield wilkinson$ chmod +X hello.py John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py -bash: ./hello.py: /usr/local/bin/python3.1^M: bad interpreter: No such file or directory John-Wilkinsons-iMac:p31summerfield wilkinson$ echo $PATH /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin John-Wilkinsons-iMac:p31summerfield wilkinson$ cat hello.py #!/usr/local/bin/python3.1 print("Hello", "World!") John-Wilkinsons-iMac:p31summerfield wilkinson$ python Python 3.1.2 (r312:79147, Mar 20 2011, 17:15:01) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python31.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1', '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages'] Thank you. Hank ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python scripting using "./"
Here is what you asked me: John-Wilkinsons-iMac:p31summerfield wilkinson$ ls -al /usr/local/bin/pytho* lrwxr-xr-x 1 root wheel 69 Mar 21 13:45 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/python3 lrwxr-xr-x 1 root wheel 76 Mar 21 13:45 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/python3-config lrwxr-xr-x 1 root wheel 71 Mar 21 13:45 /usr/local/bin/python3.1 -> ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/python3.1 lrwxr-xr-x 1 root wheel 78 Mar 21 13:45 /usr/local/bin/python3.1-config -> ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/python3.1-config lrwxr-xr-x 1 root wheel 70 Mar 21 13:45 /usr/local/bin/pythonw3 -> ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/pythonw3 lrwxr-xr-x 1 root wheel 72 Mar 21 13:45 /usr/local/bin/pythonw3.1 -> ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/pythonw3.1 John-Wilkinsons-iMac:p31summerfield wilkinson$ On May 24, 2011, at 9:20 AM, Flynn, Stephen (L & P - IT) wrote: > What is your Python executable called? You refer to it as "python" on > the command line but your "#!" line in your script refers to the > executable as "python3.1". tried it with just "python" in the #! Line? > > Check the output of 'ls -al /usr/local/bin/pytho*'... > > S. > > -Original Message- > From: tutor-bounces+steve.flynn=capita.co...@python.org > [mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of > Hank Wilkinson > Sent: Tuesday, May 24, 2011 2:10 PM > To: tutor@python.org > Subject: [Tutor] python scripting using "./" > > I am trying to do script in python using "./" > Here is a session showing "bad interpreter: No such file or directory" > Is this a python question/problem? > > Last login: Sat May 21 14:22:49 on ttys000 > John-Wilkinsons-iMac:~ wilkinson$ cd > /Users/wilkinson/Documents/py32/p31summerfield > John-Wilkinsons-iMac:p31summerfield wilkinson$ pwd > /Users/wilkinson/Documents/py32/p31summerfield > John-Wilkinsons-iMac:p31summerfield wilkinson$ ls hello.py > hello.py > John-Wilkinsons-iMac:p31summerfield wilkinson$ python hello.py > Hello World! > John-Wilkinsons-iMac:p31summerfield wilkinson$ chmod +X hello.py > John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py > -bash: ./hello.py: /usr/local/bin/python3.1^M: bad interpreter: No such > file or directory > John-Wilkinsons-iMac:p31summerfield wilkinson$ echo $PATH > /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/ > bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin > John-Wilkinsons-iMac:p31summerfield wilkinson$ cat hello.py > #!/usr/local/bin/python3.1 > > print("Hello", "World!") > John-Wilkinsons-iMac:p31summerfield wilkinson$ python > Python 3.1.2 (r312:79147, Mar 20 2011, 17:15:01) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> sys.path > ['', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > 1.zip', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > .1', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > .1/plat-darwin', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > .1/lib-dynload', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > .1/site-packages'] > > Thank you. > Hank > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > This email has been scanned for all viruses by the MessageLabs SkyScan > service. > > This email and any attachment to it are confidential. Unless you are the > intended recipient, you may not use, copy or disclose either the message or > any information contained in the message. If you are not the intended > recipient, you should delete this email and notify the sender immediately. > > Any views or opinions expressed in this email are those of the sender only, > unless otherwise stated. All copyright in any Capita material in this email > is reserved. > > All emails, incoming and outgoing, may be recorded by Capita and monitored > for legitimate business purposes. > > Capita exclude all liability for any loss or damage arising or resulting from > the receipt, use or transmission of this email to the fullest extent > permitted by law. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python scripting using "./"
John-Wilkinsons-iMac:p31summerfield wilkinson$ ls -al /usr/local/bin/python ls: /usr/local/bin/python: No such file or directory John-Wilkinsons-iMac:p31summerfield wilkinson$ ls -al /usr/local/bin/python3 lrwxr-xr-x 1 root wheel 69 Mar 21 13:45 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/python3 John-Wilkinsons-iMac:p31summerfield wilkinson$ On May 24, 2011, at 9:20 AM, Flynn, Stephen (L & P - IT) wrote: > What is your Python executable called? You refer to it as "python" on > the command line but your "#!" line in your script refers to the > executable as "python3.1". tried it with just "python" in the #! Line? > > Check the output of 'ls -al /usr/local/bin/pytho*'... > > S. > > -Original Message- > From: tutor-bounces+steve.flynn=capita.co...@python.org > [mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of > Hank Wilkinson > Sent: Tuesday, May 24, 2011 2:10 PM > To: tutor@python.org > Subject: [Tutor] python scripting using "./" > > I am trying to do script in python using "./" > Here is a session showing "bad interpreter: No such file or directory" > Is this a python question/problem? > > Last login: Sat May 21 14:22:49 on ttys000 > John-Wilkinsons-iMac:~ wilkinson$ cd > /Users/wilkinson/Documents/py32/p31summerfield > John-Wilkinsons-iMac:p31summerfield wilkinson$ pwd > /Users/wilkinson/Documents/py32/p31summerfield > John-Wilkinsons-iMac:p31summerfield wilkinson$ ls hello.py > hello.py > John-Wilkinsons-iMac:p31summerfield wilkinson$ python hello.py > Hello World! > John-Wilkinsons-iMac:p31summerfield wilkinson$ chmod +X hello.py > John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py > -bash: ./hello.py: /usr/local/bin/python3.1^M: bad interpreter: No such > file or directory > John-Wilkinsons-iMac:p31summerfield wilkinson$ echo $PATH > /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/ > bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin > John-Wilkinsons-iMac:p31summerfield wilkinson$ cat hello.py > #!/usr/local/bin/python3.1 > > print("Hello", "World!") > John-Wilkinsons-iMac:p31summerfield wilkinson$ python > Python 3.1.2 (r312:79147, Mar 20 2011, 17:15:01) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> sys.path > ['', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > 1.zip', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > .1', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > .1/plat-darwin', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > .1/lib-dynload', > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 > .1/site-packages'] > > Thank you. > Hank > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > This email has been scanned for all viruses by the MessageLabs SkyScan > service. > > This email and any attachment to it are confidential. Unless you are the > intended recipient, you may not use, copy or disclose either the message or > any information contained in the message. If you are not the intended > recipient, you should delete this email and notify the sender immediately. > > Any views or opinions expressed in this email are those of the sender only, > unless otherwise stated. All copyright in any Capita material in this email > is reserved. > > All emails, incoming and outgoing, may be recorded by Capita and monitored > for legitimate business purposes. > > Capita exclude all liability for any loss or damage arising or resulting from > the receipt, use or transmission of this email to the fullest extent > permitted by law. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python scripting using "./"
Thank you, I changed the first line to: #!/usr/bin/env/python3 then I tried again: John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py -bash: ./hello.py: /usr/bin/env/python3^M: bad interpreter: Not a directory John-Wilkinsons-iMac:p31summerfield wilkinson$ So I am getting different messages, but ... On May 24, 2011, at 9:30 AM, Flynn, Stephen (L & P - IT) wrote: > You missed a "*" from the end of the ls command but it matters not. > > Your python executable is named "/usr/local/bin/python3" so if you > change the first line of your script to... > > #!/usr/local/bin/python3 > > ...you should get along much better! :) > > S. > > -Original Message- > From: Hank Wilkinson [mailto:hwilkin...@triad.rr.com] > Sent: Tuesday, May 24, 2011 2:25 PM > To: Flynn, Stephen (L & P - IT) > Cc: tutor@python.org > Subject: Re: [Tutor] python scripting using "./" > > John-Wilkinsons-iMac:p31summerfield wilkinson$ ls -al > /usr/local/bin/python > ls: /usr/local/bin/python: No such file or directory > John-Wilkinsons-iMac:p31summerfield wilkinson$ ls -al > /usr/local/bin/python3 > lrwxr-xr-x 1 root wheel 69 Mar 21 13:45 /usr/local/bin/python3 -> > ../../../Library/Frameworks/Python.framework/Versions/3.1/bin/python3 > John-Wilkinsons-iMac:p31summerfield wilkinson$ > > On May 24, 2011, at 9:20 AM, Flynn, Stephen (L & P - IT) wrote: > >> What is your Python executable called? You refer to it as "python" on >> the command line but your "#!" line in your script refers to the >> executable as "python3.1". tried it with just "python" in the #! Line? >> >> Check the output of 'ls -al /usr/local/bin/pytho*'... >> >> S. >> >> -Original Message- >> From: tutor-bounces+steve.flynn=capita.co...@python.org >> [mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf > Of >> Hank Wilkinson >> Sent: Tuesday, May 24, 2011 2:10 PM >> To: tutor@python.org >> Subject: [Tutor] python scripting using "./" >> >> I am trying to do script in python using "./" >> Here is a session showing "bad interpreter: No such file or directory" >> Is this a python question/problem? >> >> Last login: Sat May 21 14:22:49 on ttys000 >> John-Wilkinsons-iMac:~ wilkinson$ cd >> /Users/wilkinson/Documents/py32/p31summerfield >> John-Wilkinsons-iMac:p31summerfield wilkinson$ pwd >> /Users/wilkinson/Documents/py32/p31summerfield >> John-Wilkinsons-iMac:p31summerfield wilkinson$ ls hello.py >> hello.py >> John-Wilkinsons-iMac:p31summerfield wilkinson$ python hello.py >> Hello World! >> John-Wilkinsons-iMac:p31summerfield wilkinson$ chmod +X hello.py >> John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py >> -bash: ./hello.py: /usr/local/bin/python3.1^M: bad interpreter: No > such >> file or directory >> John-Wilkinsons-iMac:p31summerfield wilkinson$ echo $PATH >> > /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/ >> bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin >> John-Wilkinsons-iMac:p31summerfield wilkinson$ cat hello.py >> #!/usr/local/bin/python3.1 >> >> print("Hello", "World!") >> John-Wilkinsons-iMac:p31summerfield wilkinson$ python >> Python 3.1.2 (r312:79147, Mar 20 2011, 17:15:01) >> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import sys >>>>> sys.path >> ['', >> > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 >> 1.zip', >> > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 >> .1', >> > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 >> .1/plat-darwin', >> > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 >> .1/lib-dynload', >> > '/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3 >> .1/site-packages'] >> >> Thank you. >> Hank >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >> This email has been scanned for all viruses by the MessageLabs SkyScan >> service. >> >> This email and any attachment to it are confidential. Unless you are
Re: [Tutor] python scripting using "./"
Thank you. John-Wilkinsons-iMac:p31summerfield wilkinson$ which python /opt/local/bin/python On May 24, 2011, at 9:27 AM, Walter Prins wrote: > 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 > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python scripting using "./"
Yes, I would love to know why it doesn't work, or what I'm doing wrong. John-Wilkinsons-iMac:p31summerfield wilkinson$ cat hello.py #!/usr/bin/env python print("Hello world") John-Wilkinsons-iMac:p31summerfield wilkinson$ chmod +X hello.py John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py -bash: ./hello.py: Permission denied John-Wilkinsons-iMac:p31summerfield wilkinson$ On May 24, 2011, at 10:02 AM, Walter Prins wrote: > > > On 24 May 2011 14:51, Hank Wilkinson wrote: > Thank you, I changed the first line to: > #!/usr/bin/env/python3 > then I tried again: > John-Wilkinsons-iMac:p31summerfield wilkinson$ ./hello.py > -bash: ./hello.py: /usr/bin/env/python3^M: bad interpreter: Not a directory > John-Wilkinsons-iMac:p31summerfield wilkinson$ > > So I am getting different messages, but ... > > Yes, the exact line to use is: > > #!/usr/bin/env python > > Note the space between "/usr/bin/env" and "python". > > If you'd like to know what's happening here I'll explain. > > Walter > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor