How to build 64-bit Python on OS X 10.6 — ONLY 64 bit, no Universal nonsense

后端 未结 4 1830
旧时难觅i
旧时难觅i 2021-01-12 15:02

I just want to build this on my development machine -- the binary install from Python.org is still 32 bits and installing extensions (MySQLdb, for example) is driving me nut

4条回答
  •  天涯浪人
    2021-01-12 15:56

    If you happen to be using MacPorts, it's as simple as specifying the variant that tells it not to compile Universal, like so:

    sudo port install python26 -universal
    

    You can view available variants using the variants command:

    % port variants python26                                                        
    python26 has the variants:
       darwin: Platform variant, selected automatically
       no_tkinter: Disable Tkinter support, which will break IDLE
       ucs4: Enable support for UCS4
       universal: Build for multiple architectures
    

    As you can see, by default on 10.6 it builds the darwin variant, which builds ONLY x86_64:

    % cd /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/
    % file python2.6
    python2.6: Mach-O 64-bit executable x86_64
    

    Compare to default python binary, which is Universal:

    % file /usr/bin/python
    /usr/bin/python: Mach-O universal binary with 3 architectures
    /usr/bin/python (for architecture x86_64):      Mach-O 64-bit executable x86_64
    /usr/bin/python (for architecture i386):        Mach-O executable i386
    /usr/bin/python (for architecture ppc7400):     Mach-O executable ppc
    

    If you're not using MacPorts, I suggest you consider it. It saves a lot of time and heartache having to manually configure and compile everything, and there is an excellent GUI interface called Porticus. All free and open source, of course!

    p.s. Never replace or rename the original system binaries! As suggested in the comments by Ned Daily:

    "Either manage access to the intended python instance by changing the search order in the PATH environment variable or, if necessary, use an absolute path like /opt/local/bin/python2.6".

提交回复
热议问题