How to build 64-bit Python on OS X 10.6 -- ONLY 64 bit, no Universal nonsense
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 nuts with trying to figure out the proper flags for each and every extension.
Clarification: I did NOT replace the system Python, I just installed the Python.org binary into its normal place at /Library/..., not /System/Library/....
Everything else seems to build 64 bit by default, and the default Python 2.6.1 was 64 bit (before I replaced it with the Python.org build figuring it was a direct replacement)`
I just want a 64 bit only build that will run on my one machine without any cruft.
Does anyone have 开发者_运维问答a simple answer?
Thanks much, ssteinerX@gmail.com
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.
精彩评论