Please see my answer here for full details, but essentially the answer is to put the package(s) needed in your plugin directory (make sure their license(s) allow for redistribution in this manner) as a separate folder, then use the following model:
try: #ST3
from .foobar import mymodule
import .baz
except ImportError: #ST2
from foobar import mymodule
import baz
for importing the modules. The main issues with your answer are that A) it is Mac-specific, B) it is ST2-specific, and C) it's not portable - you can't distribute your plugin using this method.
It would be easiest to only use pure Python modules that work with both 2.6 and 3.3 (if you want to target both ST2 and ST3). If you use a compiled module (lxml
, numpy
, whatever), you'll need to have versions compiled individually for 2.6 and 3.3 (again, if you're supporting both editor versions), and within that compiled for OS X, Linux, and Windows. Finally, for Linux and Windows you'll need both 32- and 64-bit versions (OS X is 64-bit only). The only package I'm aware of that does this is the PyV8
node/js engine for Emmet
and I think maybe 1 or 2 others. As you can see, it'd be a real pain in the neck to support and upgrade.