Re: [Tutor] python scripting using "./"
An oddity of the PATH variable in Linux (or at least Ubuntu) is that there is a folder in PATH called /home/~/bin. The ~ is replaced with your profile name. If you create that folder and put the file into it, you can invoke it from anywhere in the filesystem with just its name. On Tue, May 24, 2011 at 10:39 AM, Walter Prins wrote: > Hi Hank, > > On 24 May 2011 15:15, Hank Wilkinson wrote: > >> 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 >> > > OK you had me scratching my head for a couple of minutes, but then I tried > your steps on my Ubuntu box and managed to reproduce it. > > The problem here is you're using +X (capital X) when setting the file > execute permission. You should be using +x (lowercase x) when setting the > script to be executable. Capital X will only set the file to be executable > if it's **already** executable for some other user/group (which is not the > case in your new script's case.) Lowercase x will set it executable full > stop. > > Cheers > > Walter > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- This Apt Has Super Cow Powers - http://sourcefreedom.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python scripting using "./"
Hi Hank, On 24 May 2011 15:15, Hank Wilkinson wrote: > 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 > OK you had me scratching my head for a couple of minutes, but then I tried your steps on my Ubuntu box and managed to reproduce it. The problem here is you're using +X (capital X) when setting the file execute permission. You should be using +x (lowercase x) when setting the script to be executable. Capital X will only set the file to be executable if it's **already** executable for some other user/group (which is not the case in your new script's case.) Lowercase x will set it executable full stop. Cheers Walter ___ 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
Re: [Tutor] python scripting using "./"
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
Re: [Tutor] python scripting using "./"
On 24 May 2011 14:53, Hank Wilkinson wrote: > Thank you. > John-Wilkinsons-iMac:p31summerfield wilkinson$ which python > /opt/local/bin/python > > OK excellent.So you can either use '#!/opt/local/bin/python' in your script, or alternatively '/usr/bin/env python' (presuming that you have 'env' available.) Note the space between the /usr/bin/env" part and the "python" part. Walter ___ 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. 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 "./"
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 "./"
Hank Wilkinson wrote: > 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? It's a bash problem. The shell cannot cope with Windows line endings: ^M in the error message stands for chr(13) or Carriage Return. > -bash: ./hello.py: /usr/local/bin/python3.1^M: bad interpreter: No such > file or directory John-Wilkinsons-iMac:p31summerfield wilkinson$ echo There is a utility program called dos2unix to convert line endings, but I don't know if it's available on the Mac. $ cat -v tmp.py #!/usr/bin/python^M print "hello"^M $ ./tmp.py bash: ./tmp.py: /usr/bin/python^M: bad interpreter: No such file or directory $ dos2unix tmp.py $ ./tmp.py hello $ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python scripting using "./"
On 2011/05/24 03:10 PM, Hank Wilkinson wrote: 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 Where is the python binary actually located ? You can check with `which python` to find the location, mine was always /usr/bin/python with *nix, can't say off-hand the location with Mac. -- Christian Witts ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python scripting using "./"
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 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. 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 t
Re: [Tutor] python scripting using "./"
On Tue, May 24, 2011 at 9:10 AM, Hank Wilkinson wrote: > 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 > do you have this in first line of your file: #!/usr/bin/env python in your path you have /usr/bin. if you go there you will probably see a directory with python executable in it. -- Joel Goldstick ___ 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 "./"
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 "./"
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
Re: [Tutor] python scripting using "./"
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