How to use libxml2 with python on macOs?

馋奶兔 提交于 2019-12-09 17:55:41

问题


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?

$ python -c "import libxml2"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named libxml2

回答1:


  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

You'll need XCode installed, but like, you should already have that installed, right?




回答2:


tkone's answer is OK. But brew also can do it.

Try this,

  $ brew install libxml2 --with-python



回答3:


I don't believe the stock Python ships with the libxml2 module. You can install macports, and then do this:

$ 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.




回答4:


Just use Pypi to install python module packages, by typing :

sudo pip search libxml  and sudo pip install libxml


来源:https://stackoverflow.com/questions/9797402/how-to-use-libxml2-with-python-on-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!