applescript/python question

G

Guest

I can't seem to figure this out. I just installed Python 2.5.2 a few days ago on my OS X 10.4.11
system. It runs fine and if I type "Python -V" in the Terminal it outputs "Python 2.5.2" which is
correct. However, if I try to run a 'do shell script' in AppleScript which I'm wanting to run a Python
program, it reverts to using Python 2.3. For example, if I run this code in AppleScript:

--------------------
set p to "#!/usr/bin/python
import sys
print sys.version[:3]"
set x to do shell script "Python -c \"" & p & "\""
return x
--------------------

I get "2.3". Does anyone have any ideas why AppleScript is using the older version of Python?
Is there a way to fix this?

Thanks.

Jay
 
S

Sean DiZazzo

I can't seem to figure this out.  I just installed Python 2.5.2 a few days ago on my OS X 10.4.11
system.  It runs fine and if I type "Python -V" in the Terminal it outputs "Python 2.5.2" which is
correct.  However, if I try to run a 'do shell script' in AppleScript which I'm wanting to run a Python
program, it reverts to using Python 2.3.  For example, if I run this code in AppleScript:

--------------------
set p to "#!/usr/bin/python
import sys
print sys.version[:3]"
set x to do shell script "Python -c \"" & p & "\""
return x
--------------------

I get "2.3".  Does anyone have any ideas why AppleScript is using the older version of Python?
Is there a way to fix this?

Thanks.

Jay

Change the first line to

set p to "#!/usr/bin/env python"

That will execute the default python installation...assuming 2.5.2 is
the default. Otherwise, you can change that to the absolute path of
the 2.5.2 version.

~Sean
 
D

Diez B. Roggisch

I can't seem to figure this out. I just installed Python 2.5.2 a few days ago on my OS X 10.4.11
system. It runs fine and if I type "Python -V" in the Terminal it outputs "Python 2.5.2" which is
correct. However, if I try to run a 'do shell script' in AppleScript which I'm wanting to run a Python
program, it reverts to using Python 2.3. For example, if I run this code in AppleScript:

--------------------
set p to "#!/usr/bin/python
import sys
print sys.version[:3]"
set x to do shell script "Python -c \"" & p & "\""
return x

I guess the shebang is simply ignored - the actual interpreter is
fetched from the "Python -c"-line.

It's a bit weird that there is Python with a capital P, but what happens
if you change that to Python2.5 for example?

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top