views:

183

answers:

2

On this help page

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/python.1.html

Apple says:

CHANGING THE DEFAULT PYTHON

Using

       % defaults write com.apple.versioner.python Version 2.5

will make version 2.5 the user default when running the both the python and pythonw commands (versioner is the internal name of the version-selection software used).

This simply doesn't work!

tppllc-Mac-Pro:~ swirsky$ python --version
Python 2.7
tppllc-Mac-Pro:~ swirsky$ defaults write com.apple.versioner.python Version 2.5
tppllc-Mac-Pro:~ swirsky$ python --version
Python 2.7

and neither does the switch to make 32-bit python the default

64-BIT SUPPORT

Version 2.6 supports 64-bit execution (which is on by default). Version 2.5 only supports 32-bit execution.

Like the version of Python, the python command can select between 32 and 64-bit execution (when both are available). Use:

       % defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

to make 32-bit execution the user default (using /Library/Preferences/com.apple.versioner.python will set the system-wide default). The environment variable VERSIONER_PYTHON_PREFER_32_BIT can also be used (has precedence over the preference file):

       % export VERSIONER_PYTHON_PREFER_32_BIT=yes #

Bourne-like shells or

       % setenv VERSIONER_PYTHON_PREFER_32_BIT yes #

C-like shells

I'm down a rathole here. I'm trying to get wxpython to run. But it won't run on the Apple Python 2.7 because there's no 64-bit carbon support, and cocoa support isn't finished in wx yet.

=== UPDATE ===

Thanks for all your help! The mystery's been solved. One thing that confused me is I had no trouble running (32-bit) wxpython on my laptop (a recent i5 macbook pro), but it wouldn't run on my desktop (a recent i7 mac pro).

They both had python 2.7, and I assumed it was the same. But it wasn't!

The Mac Pro had the x86_64 build

tppllc-Mac-Pro:~ swirsky$ file `which python`
/Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O universal binary with 3 architectures
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture i386):   Mach-O executable i386
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture ppc7400):    Mach-O executable ppc
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64

and the laptop didn't:

thrilllap-2:thrillscience swirsky$ file `which python`
/Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O universal binary with 2 architectures
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture ppc):    Mach-O executable ppc
/Library/Frameworks/Python.framework/Versions/2.7/bin/python (for architecture i386):   Mach-O executable i386

I'll re-install the one without the x86_64 version on my desktop machine, as I don't need 64-bit support yet.

+2  A: 

I think the version of python which ships with OS X 10.6 is 2.6. The fact that your command line says it's 2.7 means, if I understand it correctly, you installed 2.7 by some other means. (Maybe macports, fink, or directly compiled.) Those non-Apple-provided python won't usually support Apple's versioner system. Could you run the following?

$ which python

Does it say /usr/bin/python ?

Yuji
Indeed- it could be set up in one of the user's dot files, too. Try `echo $PATH` to see if Python 2.7 is in there somewhere?
dash-tom-bang
+4  A: 

defaults write com.apple.versioner.python and VERSIONER_PYTHON_PREFER_32_BIT are Apple-developed changes and apply only to the Apple-supplied /usr/bin/python in OS X 10.6 (Python 2.6.1). You have likely installed a Python 2.7 using one of the python.org installers. There are two 2.7 installers currently available from python.org, one (for 10.5 and above) includes both 32-bit and 64-bit support. The second (for 10.3 and above, including 10.6) is 32-bit only. Presumably, you installed the first. To have it run in 32-bit mode, you can invoke it using the arch command:

$ arch -i386 python2.7

Or, if you always want to use 32-bit, you can re-install 2.7 using the other installer. Note the 64-bit installer from python.org is new in 2.7. And, unfortunately, there are a few problems with it, namely Tkinter and programs that use it (including IDLE) fail on OS X 10.6. That will be remedied in a maintenance update. If you need them on 10.6, stick to the 32-bit only installer for now.

Most likely the reason that the command python now invokes 2.7 is that the python.org installer updates your login profiles, like .bash_profile to put its framework bin directory first on your shell search PATH.

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin: # ...
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ /usr/bin/python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
$ python
Python 2.7 (r27:82508, Jul  3 2010, 21:12:11) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
$ python -c 'import sys;print("%x"%sys.maxint)'
7fffffffffffffff
$ arch -x86_64 python -c 'import sys;print("%x"%sys.maxint)'
7fffffffffffffff
$ arch -i386 python -c 'import sys;print("%x"%sys.maxint)'
7fffffff
Ned Deily