如何在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:59:55  来源:igfitidea点击:

How to use libxml2 with python on macOs?

pythonmacososx-lionlibxml2

提问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

  1. Visit ftp://xmlsoft.org/libxml2/python/and ensure this is the latest version
  2. Download it
  3. unpack it
  4. open a term and cd to that directory
  5. type sudo python setup.py install
  6. ls /Library/Python/2.7/site-packages/and you should see a bunch of libxml2 files
  7. try the test again and it should work
  1. 访问ftp://xmlsoft.org/libxml2/python/并确保这是最新版本
  2. 下载它
  3. 打开包装
  4. 打开一个术语并 cd 到该目录
  5. 类型 sudo python setup.py install
  6. ls /Library/Python/2.7/site-packages/你应该会看到一堆 libxml2 文件
  7. 再次尝试测试,它应该可以工作

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 libxml2module. 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 模块。

回答by Veelion Chong

Just use Pypito install python module packages, by typing :

只需使用Pypi安装 python 模块包,键入:

sudo pip search libxml  and sudo pip install libxml