pythonhtmltidy

Mac OS X 10.6 Python 2.7 pytidylib utidylib could not find libtidy


I am answering my own question, but because I stayed up all night figuring it out, I will hopefully save others some pain. If you are getting either of the following messages after properly installing pytidylib or utidylib, this answer may help.

Learning Python on Snow Leopard, I had installed the 32-bit version of Python 2.7 so that I could use the IDLE interpreter/editor. Stackoverflow has a great explanation why I had to do this.

When I installed utidylib, I got the following error from 'import tidy':

'OSError: Couldn't find libtidy, please make sure it is installed.'

With pytidylib, I got this error when I tried 'from tidylib import tidy_document':

'OSError: Could not load libtidy using any of these names: libtidy,libtidy.so,libtidy-0.99.so.0,cygtidy-0-99-0,tidylib,libtidy.dylib,tidy.'

If you are getting these errors, please read this answer. I hope it helps you.


Solution

  • Although it looked like the Python packages could not find the files, what was really happening was that I compiled libtidy for the wrong architecture: x86_64 instead of i386. Using the 32-bit Python installer made them incompatible.

    For neophytes like me, lipo will tell you the architecture of your files:

    $ lipo -info /Library/Frameworks/Python.framework/Versions/2.7/bin/python
    Architectures in the fat file: /Library/Frameworks/Python.framework/Versions/2.7/bin/python are: ppc i386
    
    $ lipo -info /usr/lib/libtidy.dylib
    Non-fat file: /usr/lib/libtidy.dylib is architecture: x86_64

    You may have to locate your libtidy.dylib and python files to compare. To fix the problem, you have to re-compile libtidy for i386 (or link to an i386-compiled libtidy already on your system). To re-compile for i386, use these instructions with the following modification:

    cvs -z3 -d:pserver:anonymous@tidy.cvs.sourceforge.net:/cvsroot/tidy co -P tidy
    cd tidy
    sh build/gnuauto/setup.sh
    ./configure --prefix=/usr CFLAGS="-arch i386"
    make && sudo make install
    

    This worked for me. I hope it also works for you.