2012-09-29

Installing Python 3.3 with LZMA/XZ on Mac OS X


Today's release of Python 3.3 includes the lzma module in the standard library for  LZMA/XZ files, but it didn't work 'out of the box' under Mac OS X 10.8 Mountain Lion - it requires XZ Utils. This is how I installed it.

At the time of writing Python 3.3 doesn't come pre-compiled for Mac OS X 10.8 Mountain Lion (only older versions of OS X), so I built it from source (having installed XCode via the App Store for free). However, I had a warning about _lzma not being built, and the associated test_lzma.py was skipped.

You have to install the XZ Utils library as well, I opted to do this under my home directory:

$ curl -O http://tukaani.org/xz/xz-5.0.4.tar.gz
$ tar -zxvf xz-5.0.4.tar.gz
$ cd xz-5.0.4
$ ./configure --prefix=$HOME
$ make
$ make check
$ make install

Easy enough, and now (re)install Python 3.3 which I am also installing under my home directory:

$ curl -O http://www.python.org/ftp/python/3.3.0/Python-3.3.0.tgz
$ tar -zxvf Python-3.3.0.tgz
$ cd Python-3.3.0
$ ./configure --prefix=$HOME
$ make
$ make test
$ make install

Done. Time for a quick check:

$ python3
Python 3.3.0 (default, Sep 29 2012, 19:41:44) 
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lzma
>>> dir(lzma)
['CHECK_CRC32', 'CHECK_CRC64', 'CHECK_ID_MAX', 'CHECK_NONE', 'CHECK_SHA256', 'CHECK_UNKNOWN', 'FILTER_ARM', 'FILTER_ARMTHUMB', 'FILTER_DELTA', 'FILTER_IA64', 'FILTER_LZMA1', 'FILTER_LZMA2', 'FILTER_POWERPC', 'FILTER_SPARC', 'FILTER_X86', 'FORMAT_ALONE', 'FORMAT_AUTO', 'FORMAT_RAW', 'FORMAT_XZ', 'LZMACompressor', 'LZMADecompressor', 'LZMAError', 'LZMAFile', 'MF_BT2', 'MF_BT3', 'MF_BT4', 'MF_HC3', 'MF_HC4', 'MODE_FAST', 'MODE_NORMAL', 'PRESET_DEFAULT', 'PRESET_EXTREME', '_BUFFER_SIZE', '_MODE_CLOSED', '_MODE_READ', '_MODE_READ_EOF', '_MODE_WRITE', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__initializing__', '__loader__', '__name__', '__package__', '_decode_filter_properties', '_encode_filter_properties', 'builtins', 'compress', 'decompress', 'io', 'is_check_supported', 'open']
>>> quit()

Next will be to explore if this is actually useful for things like compressed sequence files.

Note for older versions of Python (which don't come with the lzma module), you can install PylibLZMA instead (PylibLZMA SourceForge page), which requires LZMA Utils (although I haven't tried that yet - my first attempt failed at the compile stage). Update - could perhaps try PyLZMA too (PyLZMA GitHub page)? Note these don't seem to support the XZ format.

Update

I've started a backport of Python 3.3's lzma module, currently working on Python 3.1, 3.2 and 3.3 (Mac OS X and Linux), so that I can use both LZMA and XZ files on older versions of Python.

Update

Fixed XY <-> XZ typos.

Update (Jan 2013)

I've just made the first public release of my lzma backport on PyPI, tested under Python 2.6, 2.7 and 3.0 to 3.3 on Mac OS X and Linux. Windows support is pending...

No comments:

Post a Comment