2010-10-31 105 views
2

我正在回答我自己的问题,但是因为我整晚都想了解它,所以我希望能够为别人节省一些痛苦。如果在正确安装pytidylibutidylib后收到以下消息,此答案可能会有所帮助。Mac OS X 10.6 Python 2.7 pytidylib utidylib找不到libtidy

在Snow Leopard上学习Python,我安装了Python 2.7的32位版本,以便我可以使用IDLE解释器/编辑器。 Stackoverflow有一个伟大的explanation为什么我必须这样做。

当我安装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.'

如果您收到这些错误,请阅读这个答案。我希望它能帮助你。

回答

0

尽管它看起来像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 for i386(或者链接到已经在系统上的i386编译的libtidy)。要重新编译的i386,使用these instructions作以下修改:

cvs -z3 -d:pserver:[email protected]:/cvsroot/tidy co -P tidy 
cd tidy 
sh build/gnuauto/setup.sh 
./configure --prefix=/usr CFLAGS="-arch i386" 
make && sudo make install 

这为我工作。我希望它也适用于你。

4

我在Linux上遇到类似的问题(请参阅下面的堆栈跟踪)。 pytidylib == 0.2.1在Ubuntu 11.10(Python 2.7)和Gentoo(Python 2.6)的virtualenv中与pip一起安装。 在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 
---------------------------------------------------------------------- 
0

我有同样的问题。我安装了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到我的项目文件夹,它就解决了。