views:

715

answers:

4

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, [email protected]

+6  A: 

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

jathanism
Seems like -universal flag *should* compile "Universal"---if so, you may want to edit the first line.
telliott99
Thanks! I got a couple of early OS X systems completely mutilated with earlier versions of both Fink and MacPorts and have shied away since then. I'm beginning to feel like OS X is like a beautiful but very high maintenance woman; nice to look at and play with, but when there's work to do, more of a hindrance than a help.
@telliot99 One would specify `+universal` to include it, `-universal` would exclude it. However it's excluded by default, on 10.6 so it would be extraneous.
jathanism
@ssteiner: Mac OS X is just like any other *nix system except that it does not include any package manager by default like others (RPM, Apt, etc.). Most people don't compile source by hand anymore because it sucks, so we leave it up to the binary distributions or package managers to do it for us. One is left to choose their own and MacPorts is the best IMO.
jathanism
Do not rename the original system binaries, i.e. /usr/bin/python2.6 or /usr/bin/python. Anything under /usr/bin is considered part of OS X and managed by Apple. 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`.
Ned Deily
Agreed in practice. Using alternative binaries is always the best choice. :)
jathanism
+4  A: 

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
Ned Deily
I installed MacPorts, and Python and mysqldb and damn if I don't get the same flippin' error I was getting trying to build it myself.django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dynamic module does not define init function (init_mysql)Thanks for the help anyway, now...how do I uninstall that MacPorts thing?
I think I have a very, very tangled up system. Some parts coming in properly from the virtualenv I created, other parts coming in from the Python.org install, yikes. All seems very familiar from my previous experiences with both MacPorts and Fink. Seems like I'd have to uninstall the previously source/Python.org stuff completely including MySQL itself. Oh boy.
Are you sure your Django instance is using the MacPorts Python2.6? If you had mentioned Django, I would have suggested you also pull it in from MacPorts as well: `sudo port install py26-django`. Same thing for py26-virtualenv or other packages. Works for me running Django in development server mode. If you are trying to run this under Apache, it gets more complicated.
Ned Deily
Take a deep breath! Stick to MacPorts as much as possible and chances are it will all work. But if you decide you really don't want to use MacPorts packages, first, simply remove /opt/local/bin from your $PATH and any shell shebang lines. Then you can use `sudo port -f uninstall installed` to remove them all.
Ned Deily
And, of course, you'll need to recreate your virtualenv after you've installed it from MacPorts. Also, make sure you don't have the python.org python on your $PATH: /Library/Frameworks/Python ... and you do have MacPorts first. Also see edit above about python_select.
Ned Deily
I agree with everything Ned said. Go Ned!
jathanism
Yes, I created the virtualenv properly and, unfortunately, need trunk from some things (django, twisted) so I've got to install manually.I took a deep breath, a stiff drink (of tea), nuked the virtualenv, logged out, went back in, and re-did everything.Happy to say that I'm now running 64 bit Python 2.6.4 with MacPorts, along with a full set of MySQL and supporting libs just fine.Now the real issue is how to clean up all the stuff I've installed by hand (MySQL, other Pythons, etc.).Thanks all for your help and suggestions!ssteinerX
Yay! Not knowing how you originally attempted to install MySQL, I can only guess: the installers from mysql.com usually put things in /usr/local. I've documented how to uninstall a python.org-installed OS X Python here: http://bugs.python.org/issue7107
Ned Deily
P.S. If you find an acceptable answer to a question you pose on StackOverflow, it's considered good etiquette to either mark the answer as accepted (so that the answerer receives reputation points) or to expand on your question and/or leave comments until someone comes up with an acceptable answer.
Ned Deily
+2  A: 

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.

JonG
+2  A: 

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.

Bryan Ross
Interesting. For me, as I would expect, the configure step blows up with the parameters in your example. Actually you don't need any of the FLAGS or `--with-universal-archs` when building on a 64-bit-capable 10.6 system. But once you get to the end, you'll probably find that one or more standard library modules did not build correctly, like `_tkinter` or `_curses_panel` or something else. Their absence may not be the end of the world for your use but this is *one* of the reasons why I recommend using a binary installer or a package manager, like MacPorts: to get the little details right.
Ned Deily
Ahhh I see. Well, I didn't have a problem with _curses_panel, but that's probably because I custom build that myself as well. And I never needed tkinter either.
Bryan Ross