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

微笑、不失礼 提交于 2019-12-01 04:25:26

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".

The simplest solution is pull everything you need from MacPorts:

$ sudo port selfupdate
$ sudo port install python26 +no_tkinter -universal py26-mysqldb -universal

That will install python2.6, the MySQLdb adapter, and the necessary MySQL client libraries. I suggest adding the no_tkinter variant unless you really need tkinter; there were some issues with the MacPorts version of Tk on 10.6.

EDIT: Note, the MacPorts Python will be installed as /opt/local/bin/python2.6. You may need to adjust your shell $PATH to ensure /opt/local/bin is on it before /usr/local/bin and /usr/bin. If you want /opt/local/bin/python to refer to the MacPorts python2.6, do the above and:

$ sudo port install python_select
$ sudo python_select python26

Always macports... sheesh

This is what I did:

~: wget http://python.org/ftp/python/2.6.5/Python-2.6.5.tar.bz2
~: tar xjf Python-2.6.5.tar.bz2
~: cd Python-2.6.5
~: ./configure ./configure MACOSX_DEPLOYMENT_TARGET=10.6 --enable-framework --with-universal-archs="64-bit" CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64"
~: make -j6
~: sudo make install

Might be a little redundant on the FLAGS stuff, but it worked.

Once you do get 64-bit Python setup using the methods outlined above above, I also found this blog post by Aaron Meurer helpful for verifying that Python is in fact installed as 64-bit. The post also talks about running 64-bit Python alongside a 32-bit installation, which I guess is useful for some purposes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!