Python distutils not using correct version of gcc

后端 未结 4 2001
离开以前
离开以前 2020-12-16 05:44

I am trying to compile a package on Mac OSX 10.6.5. The package\'s install script relies on distutils. The problem is that the computer\'s default gcc is version 4.2 (I de

4条回答
  •  清酒与你
    2020-12-16 05:58

    To force distutils to use a separate compiler, you can redefine a few variables via the environment. First, find out what distutils is using as defaults:

    >>> from distutils import sysconfig
    >>> sysconfig.get_config_var('LDSHARED')
    'gcc-4.0 -Wl,-F. -bundle -undefined dynamic_lookup'
    >>> sysconfig.get_config_var('CC')
    'gcc-4.0'
    

    Next you need to redefine those, substituting in the version of gcc you'd like to use:

    % LDSHARED="gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup" CC=gcc-4.2 \
        /usr/bin/python setup.py build_ext
    

    Keep in mind that the sysconfig defaults are pulled from the Makefile which was originally used to compile python, so fudging with them may produce unintended results:

    >>> path = sysconfig.get_python_lib(plat_specific=1, standard_lib=1)
    >>> os.path.join(path, 'config', 'Makefile')
    '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/Makefile'
    

提交回复
热议问题