如何在 macOS 上将 libxml2 与 python 一起使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9797402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use libxml2 with python on macOs?
提问by John Mee
I'm on OSX Lion and I have libxml2 installed (by default) and I have python installed (by default) but they don't talk to one another. What's the simplest way to make this work on Lion?
我在 OSX Lion 上安装了 libxml2(默认情况下),并且安装了 python(默认情况下),但它们不会相互通信。在 Lion 上进行这项工作的最简单方法是什么?
$ python -c "import libxml2"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named libxml2
回答by tkone
- Visit ftp://xmlsoft.org/libxml2/python/and ensure this is the latest version
- Download it
- unpack it
- open a term and cd to that directory
- type
sudo python setup.py install
ls /Library/Python/2.7/site-packages/
and you should see a bunch of libxml2 files- try the test again and it should work
- 访问ftp://xmlsoft.org/libxml2/python/并确保这是最新版本
- 下载它
- 打开包装
- 打开一个术语并 cd 到该目录
- 类型
sudo python setup.py install
ls /Library/Python/2.7/site-packages/
你应该会看到一堆 libxml2 文件- 再次尝试测试,它应该可以工作
You'll need XCode installed, but like, you should already have that installed, right?
您需要安装 XCode,但是您应该已经安装了它,对吧?
回答by jeswang
tkone's answer is OK. But brew also can do it.
tkone 的回答是可以的。但是 brew 也可以做到。
Try this,
试试这个,
$ brew install libxml2 --with-python
回答by larsks
I don't believe the stock Python ships with the libxml2
module. You can install macports, and then do this:
我不相信该libxml2
模块附带的股票 Python 。您可以安装macports,然后执行以下操作:
$ sudo port install py27-libxml2
...and after a short wait while everything installs, end up with Python 2.7, libxml2, and the libxml2 Python module.
...在一切安装完毕后,经过短暂的等待,最终得到 Python 2.7、libxml2 和 libxml2 Python 模块。