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

I just want to create this on my development machine - the binary installation from Python.org is still 32 bits, and installing extensions (like MySQLdb) makes me go crazy trying to determine the correct flags for each and every extension.

Clarification: I did NOT replace the Python system, I just installed the Python.org binary in its usual place in / Library / ..., not / System / Library / ....

Everything else is likely to build 64 bits by default, and by default Python 2.6.1 is 64-bit (before I replaced it with the Python.org assembly, indicating that it was a direct replacement) `

I just want to build only a 64-bit version that will work on my machine without any problems.

Does anyone have a simple answer?

Thank you very much, ssteinerX@gmail.com

+6
python x86-64 64bit osx-snow-leopard macos
source share
4 answers

If you use MacPorts , it is as simple as specifying an option that tells it not to compile Universal, for example:

sudo port install python26 -universal 

You can view the available options using the options 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 in 10.6 it creates 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 

Comparison with the 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 are not using MacPorts, I suggest you consider it. It saves a lot of time and suffering to manually configure and compile everything, and there is an excellent GUI called Porticus . All free and open source, of course!

ps Never replace or rename the original system binaries! As suggested in the comments of Ned Daily:

"Either control access to the python instance by changing the search order in the PATH environment variable or, if necessary, use an absolute path such as / opt / local / bin / python 2.6."

+11
source share

The easiest solution is to pull everything you need from MacPorts:

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

This will install python2.6, the MySQLdb adapter, and the required MySQL client libraries. I suggest adding the no_tkinter option if you really don't need tkinter; There were some problems with the TK MacPorts version at 10.6.

EDIT: note that MacPorts Python will be installed as /opt/local/bin/python2.6 . You may need to configure the $ PATH shell to provide / opt / local / bin on it before / usr / local / bin and / usr / bin. If you want / opt / local / bin / python to refer to MacPorts python2.6, follow the steps above and:

 $ sudo port install python_select $ sudo python_select python26 
+5
source share

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 

It may be a bit redundant on FLAGS, but it worked.

+5
source share

Once you get the 64-bit setup of Python using the methods described above, I also found this Aaron Meurer blog post useful for making Python actually installed as 64-bit. The post also talks about running 64-bit Python along with a 32-bit installation, which I think is useful for some purposes.

+3
source share

All Articles