在 Mac 10.6.x 上使用内置 libxml2
据我所知,Mac OS 10.6.x 包含 libxml2 的内置版本。
我觉得这里很愚蠢,但是为什么这不起作用呢?
python -c "import libxml2"
我是否缺少一些使该库可以在 Python 中访问的步骤?
which python
...返回:
/usr/bin/python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
...所以在我看来我正在使用默认的Python。
我找到了很多关于在旧版本 Mac OS 上安装新版本 libxml2 的旧说明,但没有找到关于仅使用 10.6.x 上附带的内容的说明。如果可能的话,我更喜欢使用内置的东西而不是 MacPorts。
I understand that Mac OS 10.6.x contains a built-in version of libxml2.
I feel pretty stupid here, but then why doesn't this work?
python -c "import libxml2"
Is there some step I'm missing that makes the library accessible in Python?
which python
...returns:
/usr/bin/python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
... so it looks to me like I'm using the default python.
I was able to find lots of older instructions for installing new versions of libxml2 on older versions of Mac OS, but nothing about just using what it comes with on 10.6.x. I prefer to use the built-in stuff instead of MacPorts if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一篇文章,解释了如何在 OS X 上为 python 安装 libxml2: http://lsimons.wordpress.com/2008/08/31/how-to-install-lxml-python-module-on-mac-os- 105-豹/
Here is a post that explains how to install libxml2 for python on OS X: http://lsimons.wordpress.com/2008/08/31/how-to-install-lxml-python-module-on-mac-os-105-leopard/
几乎可以肯定,您拥有 libxml2(随操作系统一起提供),但您可能缺少 Python 绑定,而 Python 绑定似乎并没有。这将是 /Library/Python 或 /Library/Frameworks/Python 树中名为“libxml2mod.so”的共享库。我认为没有任何方法可以避免安装某些东西,MacPorts 是一种很好的方法。不过,您可以使用内置的 libxml2,只需安装绑定即可。
You almost certainly have libxml2 -- which comes with the OS -- but you're likely missing the Python bindings, which don't seem to. That would be a shared library named something like "libxml2mod.so" inside the /Library/Python or /Library/Frameworks/Python trees. I don't think there's any way to avoid installing something, MacPorts being one fine way to do so. You can use the inbuilt libxml2, though, and just install the bindings.