手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Python中lxml模块的安装

[日期:2015-02-23] 来源:Linux社区  作者:杰瑞26 [字体:大 中 小]

lxml是Python中与XML及HTML相关功能中最丰富和最容易使用的库。lxml并不是Python自带的包,而是为libxml2和libxslt库的一个Python化的绑定。它与众不同的地方是它兼顾了这些库的速度和功能完整性,以及纯Python API的简洁性,与大家熟知的ElementTree API兼容但比之更优越!但安装lxml却又有点麻烦,因为存在依赖,直接安装的话用easy_install, pip都不能成功,会报gcc错误。下面列出来Windows、Linux下面的安装方法: 

【Windows系统】

先确保Python已经安装好,环境变量也配置好了,相应的的easy_install、pip也安装好了.

1. 执行 pip install virtualenv

  1. C:\>pip install virtualenv 
  2. Requirement already satisfied (use --upgrade to upgrade): virtualenv in c:\python27\lib\site-package 
  3. s\virtualenv-12.0.4-py2.7.egg 

 

2. 从官方网站下载与系统,Python版本匹配的lxml文件:

http://pypi.python.org/pypi/lxml/2.3/  

NOTE:

比如说我的电脑是Python 2.7.4, 64位操作系统,那么我就可以下载

  1. lxml-2.3-py2.7-win-amd64.egg (md5)     # Python Egg  
  2. 或 
  3. lxml-2.3.win-amd64-py2.7.exe (md5)     # MS Windows installer 

3. 执行 easy_install lxml-2.3-py2.7-win-amd64.egg

  1. D:\Downloads>easy_install lxml-2.3-py2.7-win-amd64.egg    # 进入该文件所在目录执行该命令  
  2. Processing lxml-2.3-py2.7-win-amd64.egg 
  3. creating c:\python27\lib\site-packages\lxml-2.3-py2.7-win-amd64.egg 
  4. Extracting lxml-2.3-py2.7-win-amd64.egg to c:\python27\lib\site-packages 
  5. Adding lxml 2.3 to easy-install.pth file 
  6.  
  7.  
  8. Installed c:\python27\lib\site-packages\lxml-2.3-py2.7-win-amd64.egg 
  9. Processing dependencies for lxml==2.3 
  10. Finished processing dependencies for lxml==2.3 

NOTE:

1. 可用exe可执行文件,方法更简单直接安装就可以

2. 可用easy_install安装方式,也可以用pip的方式

  1. #再执行下,就安装成功了!  
  2. >>> import lxml     
  3. >>>   
3. 如用pip安装,常用命令就是:
  • pip install simplejson                      # 安装Python包
  • pip install --upgrade simplejson          # 升级Python包
  • pip uninstall simplejson                    # 卸载Python包

 

4. 如用Eclipse+Pydev的开发方式,需要移除旧包,重新加载一次

 

  • Window --> Preferences --> PyDev --> Interperter-python   # 否则导包的时候会报错 
【Linux系统】

因为lxml依赖的包如下:

libxml2, libxml2-devel, libxlst, libxlst-devel, python-libxml2, python-libxslt

所以安装步骤如下:

第一步: 安装 libxml2

  • $ sudo apt-get install libxml2 libxml2-dev  
第二步: 安装 libxslt
  • $ sudo apt-get install libxlst libxslt-dev 
第三步: 安装 python-libxml2 和 python-libxslt
  • $ sudo apt-get install python-libxml2 python-libxslt
第四步: 安装 lxml
  • $ sudo easy_install lxml 

参考官方文档:

http://codespeak.net/lxml/installation.html

--------------------------------------分割线 --------------------------------------

CentOS上源码安装Python3.4  http://www.linuxidc.com/Linux/2015-01/111870.htm

《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm

《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htm

Python脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm

在Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htm

Python 语言的发展简史 http://www.linuxidc.com/Linux/2014-09/107206.htm

Python 的详细介绍:请点这里
Python 的下载地址:请点这里 

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-02/113881.htm

linux
相关资讯       Python lxml  lxml安装  lxml 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款