Reputation: 12367
I recently installed python 2.6.5 over 2.6.1 on OS X. Everything works fine except when I try executing python scripts via the Applescript editor. If I execute the following line I get version 2.6.1:
Applescript:
do shell script "python -c \"from sys import version; print version\""
But if I execute the similar line in the OS X terminal i get version 2.6.5:
OS X terminal:
python -c "from sys import version; print version"
What could be wrong? Can this somehow be easily fixed?
Upvotes: 1
Views: 1317
Reputation: 1
The mac default install places python in /usr/bin, the python installer places it in frameworks with sym links in /usr/local/bin. Just remove the old version in /usr/bin and create new sym links
ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/python /usr/bin/python
Upvotes: 0
Reputation: 1136
The Python 2.6.5 installer modifies your ~/.bash_profile
file to put Python 2.6.5's bin
directory at the start of your $PATH
, ahead of /usr/bin
which is where the OS's default Python interpreter lies. That profile is automatically read when you log in via Terminal, but not when using do shell script
. You either need to specify the full path to the python
executable you want (probably the best option), or you could have your script read the bash profile beforehand (though be aware that do shell script
uses sh
, not bash
):
do shell script ". ${HOME}/.bash_profile; python -c 'import sys; print(sys.version)'"
Upvotes: 0
Reputation: 34195
I won't recommend overwriting system-installed python
(or whatever UNIX commands,) because some of the system app might depend on the quirk of a particular version of python
installed.
It's quite customary these days to install another distinct copy of python
(or perl
or ruby
) in an entirely different path.
Then you set up the path appropriately in .profile
etc. in the case of bash so that in the command line python
you installed will be chosen.
But note that the GUI app inherits the environment variables from the system and don't read .profile
or whatever. There's a way to change PATH
environment variable seen by the GUI apps (see here), but I don't recommend it.
Where did you install your python
2.6.5? Say it's in
/usr/local/bin/python
Then in your AppleScript code you can just say
do shell script "/usr/local/bin/python -c ... ."
Upvotes: 1