Windows下Python安装lxml

发布时间:2019-09-07 08:12:42编辑:auto阅读(1886)

    推荐安装方式:命令行安装

    pip install lxml==3.4.4

    easy_install lxml==3.4.4

    会自动下载lxml-3.4.4-cp27-none-win32.whl安装

    cp27表示是python2.7

    不指定版本号的话,默认会下载最新版(3.5.0)源码编译安装,编译过程中会提示缺少libxml2和libxslt依赖


    github源码地址:https://github.com/lxml/lxml

    lxml官网:http://lxml.de/installation.html#source-builds-on-ms-windows


    参考文章:

    http://blog.csdn.net/anwenxixi/article/details/45332435



    不推荐安装方式:源码安装


    下载lxml

    https://pypi.python.org/packages/source/l/lxml/lxml-3.3.3.tar.gz

    解压后在解压文件下运行命令python setup.py install

    提示缺少 Microsoft Visual C++ Compiler for Python 2.7

    下载网址:http://www.microsoft.com/en-us/download/details.aspx?id=44266


    继续执行报错:

    lxml-3.3.3\src\lxml\includes\etree_defs.h(9) : fatal error C1083: Cannot open include file: 'libxml/xmlversion.h': No such file or directory


    缺少libxml/xmlversion.h文件

    下载libxml2已编译包:http://xmlsoft.org/sources/win32/libxml2-2.7.8.win32.zip

    解压之后将include目录下的libxml文件夹(含xmlversion.h)拷贝到lxml-3.3.3\src\lxml\includes文件夹下


    继续执行python setup.py install

    报错:

    lxml-3.3.3\src\lxml\includes\etree_defs.h(13) : fatal error C1083: Cannot open include file: 'libxslt/xsltconfig.h': No such file or directory

    libxslt依赖libxml2所以要先装libxml2再装libxslt

    下载地址:

    http://xmlsoft.org/sources/win32/libxslt-1.1.26.win32.zip

    解压将include目录下的libxslt文件夹(含xsltconfig.h)和libexslt文件夹拷贝到lxml-3.3.3\src\lxml\includes文件夹下


    继续执行python setup.py install

    报错:

    lxml-3.3.3\src\lxml\includes\libxml/encoding.h(28) : fatal error C1083: Cannot open include file: 'iconv.h': No such file or directory


    iconv.h  linux系统有这文件,windows费劲

    缺少iconv.h,下载地址:http://gnuwin32.sourceforge.net/packages/libiconv.htm

    解压将libiconv-1.9.2-1-src\src\libiconv\1.9.2\libiconv-1.9.2\include文件夹下的iconv.h复制到lxml-3.3.3\src\lxml\includes文件夹下



    LINK : fatal error LNK1181: cannot open input file 'libxslt.lib'


    最后没安装成功放弃了,还是在linux下安装吧,国外论坛上有人说可以安装visual studio 2008就可以不需要这么麻烦,没实践过不知是否可行


    参考文章:

    python第三方库lxml源码安装&&使用笔记

    http://www.360doc.com/content/14/1203/17/18578054_430141004.shtml


关键字