Mac OS X 10.6 Python 2.7 pytidylib utidylib 找不到 libtidy
我在回答自己的问题,因为我熬夜搞明白了这些,希望能帮到其他人。如果你在正确安装了 pytidylib 或 utidylib 后,遇到以下任意一条错误信息,这个回答可能对你有帮助。
我在学习Python的时候,使用的是Snow Leopard系统,安装了32位的Python 2.7,这样我才能用IDLE这个解释器/编辑器。Stackoverflow上有个很好的解释,讲了我为什么要这么做。
当我安装utidylib时,运行'import tidy
'时出现了以下错误:
'OSError: Couldn't find libtidy, please make sure it is installed
.'
而在使用pytidylib时,当我尝试'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.
'
如果你遇到这些错误,请仔细阅读这个回答。希望能对你有所帮助。
3 个回答
我也遇到过同样的问题。我安装了tidylib,但还是出现了下面的错误。
raise OSError("Could not load libtidy using any of these names: %s" % (",".join(LIB_NAMES)))
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
然后我把/usr/bin/tidy这个文件复制到我的项目文件夹里,问题就解决了。
我在Linux上遇到了类似的问题(下面是错误信息)。我在Ubuntu 11.10(Python 2.7)和Gentoo(Python 2.6)上,都是用pip在虚拟环境中安装了pytidylib==0.2.1。然后在Ubuntu上安装了apt-get install libtidy-dev
,在Gentoo上安装了emerge app-text/htmltidy
,这样就解决了问题。
---------------------------------------------------------------------- File "/home/andre/Progz/some_site/djcode/apps/default/tests.py", line ?, in default.tests.__test__.doctest Failed example: from tidylib import tidy_document Exception raised: Traceback (most recent call last): File "/home/andre/Progz/some_site/lib/python2.6/site-packages/django/test/_doctest.py", line 1267, in __run compileflags, 1) in test.globs File "", line 1, in from tidylib import tidy_document File "/home/andre/Progz/some_site/lib/python2.6/site-packages/tidylib/__init__.py", line 71, in raise OSError("Could not load libtidy using any of these names: %s" % (",".join(LIB_NAMES))) 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 ----------------------------------------------------------------------
虽然看起来Python的包找不到文件,但实际上发生的事情是我编译的libtidy不适合我的电脑架构:我用了x86_64,而应该用i386。使用32位的Python安装程序导致它们不兼容。
对于像我这样的新手,lipo
可以告诉你文件的架构:
$ 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
你可能需要找到你的libtidy.dylib和Python文件进行比较。要解决这个问题,你需要重新编译libtidy为i386(或者链接到你系统上已经编译好的i386版本的libtidy)。要重新编译为i386,可以参考这些说明,并做以下修改:
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
这个方法对我有效。希望对你也有帮助。