tags:

views:

26

answers:

2

I am trying to install a Python package that requires running gcc 4.2. My gcc is pointing correctly to gcc-4.2, i.e.

$ gcc -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5664~38/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5664)

However, my python is built using gcc 4.0, i.e.

$ python
Python 2.5.4 (r254:67917, Dec 23 2008, 15:47:06) 
[GCC 4.0.1 (Apple Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Is there any way I can re-build Python on GCC 4.2 without having to reinstall all my Python packages?

My operating system is Mac OS 10.6.

NOTE: It will not help me to just point gcc to gcc-4.0 -- I need to use gcc-4.2.

A: 

This is most likely an issue with distutils, you shouldn't need to recompile python, or reinstall any packages.

Have you checked to see what version your CC environment variable is set to? It may very well still be set to 4.0. You can try:

export CC=gcc-4.2
python setup.py build

You could also take a look at:

/Library/Frameworks/Python.framework/Versions/Current/lib/python2.5/config/Makefile

Which is where distutils gets its build settings from.

Andrew
Thanks; this was helpful.
k-g-f
+2  A: 

On current OS X Pythons, Distutils tries to ensure that C extension modules are built using the same GCC and MACOSX_DEPLOYMENT_TARGET (ABI) as the Python interpreter itself was. This ensures that there won't be conflicts with the underlying system libraries.

But if you are on OS X 10.6, then the Python version you show is not one of the Apple-supplied Pythons, both of which are built with gcc-4.2. Chances are you have an older python.org 2.5 also installed with symlinks into /usr/local/bin.

# OS X 10.6.4
$ /usr/bin/python -c 'import sys;print(sys.version)'
2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)]
$ /usr/bin/python2.6 -c 'import sys;print(sys.version)'  # same as above
2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)]
$ /usr/bin/python2.5 -c 'import sys;print(sys.version)'
2.5.4 (r254:67916, Feb 11 2010, 00:50:55) 
[GCC 4.2.1 (Apple Inc. build 5646)]
$ /usr/local/bin/python2.5 -c 'import sys;print(sys.version);print(sys.executable)'
2.5.4 (r254:67917, Dec 23 2008, 14:57:27) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)]
/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python

which python will tell you which Python is being invoked. Either use an absolute path to the interpreter you want or change your shell PATH or remove the old Python 2.5.

Ned Deily
Thanks! This fixed it.
k-g-f