如何在Windows上安装lxml

我试图用Python 3.4在我的Windows 8.1笔记本电脑上安装lmxl ,并且失败了。

首先,我尝试了简单明了的解决scheme: pip install lxml 。 但是,这不起作用。 这就是它说的:

 Downloading/unpacking lxml Running setup.py (path:C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml\setup.py) egg_info for package lxml Building lxml version 3.4.2. Building without Cython. ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n" ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) warning: no previously-included files found matching '*.py' Installing collected packages: lxml Running setup.py install for lxml Building lxml version 3.4.2. Building without Cython. ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n" ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt building 'lxml.etree' extension C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) error: Unable to find vcvarsall.bat Complete output from command C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\CARTE_~1\\AppData\\Local\\Temp\\pip_build_carte_000\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\CARTE_~1\AppData\Local\Temp\pip-l8vvrv9g-record\install-record.txt --single-version-externally-managed --compile: Building lxml version 3.4.2. Building without Cython. ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n" ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt running install running build running build_py creating build creating build\lib.win32-3.4 creating build\lib.win32-3.4\lxml copying src\lxml\builder.py -> build\lib.win32-3.4\lxml copying src\lxml\cssselect.py -> build\lib.win32-3.4\lxml copying src\lxml\doctestcompare.py -> build\lib.win32-3.4\lxml copying src\lxml\ElementInclude.py -> build\lib.win32-3.4\lxml copying src\lxml\pyclasslookup.py -> build\lib.win32-3.4\lxml copying src\lxml\sax.py -> build\lib.win32-3.4\lxml copying src\lxml\usedoctest.py -> build\lib.win32-3.4\lxml copying src\lxml\_elementpath.py -> build\lib.win32-3.4\lxml copying src\lxml\__init__.py -> build\lib.win32-3.4\lxml creating build\lib.win32-3.4\lxml\includes copying src\lxml\includes\__init__.py -> build\lib.win32-3.4\lxml\includes creating build\lib.win32-3.4\lxml\html copying src\lxml\html\builder.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\clean.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\defs.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\diff.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\ElementSoup.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\formfill.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\html5parser.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\soupparser.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\usedoctest.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\_diffcommand.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\_html5builder.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\_setmixin.py -> build\lib.win32-3.4\lxml\html copying src\lxml\html\__init__.py -> build\lib.win32-3.4\lxml\html creating build\lib.win32-3.4\lxml\isoschematron copying src\lxml\isoschematron\__init__.py -> build\lib.win32-3.4\lxml\isoschematron copying src\lxml\lxml.etree.h -> build\lib.win32-3.4\lxml copying src\lxml\lxml.etree_api.h -> build\lib.win32-3.4\lxml copying src\lxml\includes\c14n.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\config.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\dtdvalid.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\etreepublic.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\htmlparser.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\relaxng.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\schematron.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\tree.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\uri.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\xinclude.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\xmlerror.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\xmlparser.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\xmlschema.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\xpath.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\xslt.pxd -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\etree_defs.h -> build\lib.win32-3.4\lxml\includes copying src\lxml\includes\lxml-version.h -> build\lib.win32-3.4\lxml\includes creating build\lib.win32-3.4\lxml\isoschematron\resources creating build\lib.win32-3.4\lxml\isoschematron\resources\rng copying src\lxml\isoschematron\resources\rng\iso-schematron.rng -> build\lib.win32-3.4\lxml\isoschematron\resources\rng creating build\lib.win32-3.4\lxml\isoschematron\resources\xsl copying src\lxml\isoschematron\resources\xsl\RNG2Schtrn.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl copying src\lxml\isoschematron\resources\xsl\XSD2Schtrn.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl creating build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1 copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_abstract_expand.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1 copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_dsdl_include.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1 copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_message.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1 copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_skeleton_for_xslt1.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1 copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_svrl_for_xslt1.xsl -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1 copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\readme.txt -> build\lib.win32-3.4\lxml\isoschematron\resources\xsl\iso-schematron-xslt1 running build_ext building 'lxml.etree' extension C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) error: Unable to find vcvarsall.bat ---------------------------------------- Cleaning up... Command C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\CARTE_~1\\AppData\\Local\\Temp\\pip_build_carte_000\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\CARTE_~1\AppData\Local\Temp\pip-l8vvrv9g-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml Storing debug log for failure in C:\Users\carte_000\pip\pip.log 

那么我看了这个叫做互联网这个伟大而有用的东西,很多人都有需要libxml2libxlst错误。 他们推荐一个名叫Christoph Gohlke的页面,他为一堆软件包提供了一些二进制的东西。 你可以在这里find它(快速链接到lxml部分 )。

所以在我放弃尝试为pipfindlibxml2和libxslt后,我决定去那里,发现绝对的下载量。 我知道我需要一个64位的,但我不知道我需要哪个“ cp ”。

所以给我一个解决方法或Gohlke指数方法的答案会很好。

Solutions Collecting From Web of "如何在Windows上安装lxml"

或者你也可以去Christoph的Gohlke的Python页面 ,然后下载正确的lxml文件。 (通常,因为我使用python 3.4,我有一个窗口,我下载了lxml-3.4.4-cp34-none-win32.whl)

转到它所在的文件夹。点击背景(所以没有选择任何东西),然后左移+右键同时点击打开的命令窗口。 然后键入C:/ Python34 / Scripts / pip install“您正在下载的文件的名称.whl”

在这种情况下,它将是C:/ Python34 / Scripts / pip install“lxml-3.4.4-cp34-none-win32.whl”

现在点击进入。 这对我很好,输入报价后,你也可以按tab,它应该填写正确的一个给你。

首先,在下面的评论中,我下载了lxml-3.4.2-cp34-none-win_amd64.whl文件,并尝试用pip install来打开它,但是它只是告诉我这不是我的系统上的有效轮盘文件,或者一些东西。

然后,我下载了win_32文件,它工作! 也许这是因为我有一个英特尔处理器,AMD64毫无疑问只适用于AMD处理器。

这些说明适用于使用Python3.4的Windows7或Windows8

但是 ,随着python的发布和其他各种先决条件的变化/演变,它们应该可以用于各种版本:

  1. 安装Python3.4
    1. 从这里的下载页面下载最新版本的Python3.4
      • 直接链接为Win32 MSI安装程序 – > 这里
    2. 只需运行MSI即可安装python。 它将在注册表中注册,并出现在“添加/删除程序”中。
    3. 注意:我遵循的说明假设您选择在Python安装向导期间询问时将python安装到C:\python34\的默认路径
  2. 控制面板>系统>高级系统设置链接(高级选项卡)>环境变量(按钮) ,将这些目录添加到PATH环境变量中,将C:\python33\C:\python34\scripts文件夹添加到系统路径。
  3. 安装OpenSSL
    1. 从这里下载Win32 OpenSSL页面 ,用于您的Windows和PC体系结构的版本
    2. 下载适用于您的Windows和PC体系结构版本的Visual C ++ 2008可再发行组件
    3. 为您的Windows和体系结构下载OpenSSL (常规版本,而不是轻量级版本)
    4. c:\openssl-win32\bin (或类似的)目录添加到PATH ,就像上面添加C:\python34C:\python34\scripts
  4. 安装Setuptoolsget-pip.py应该为你安装Setuptools),但是,以防万一…
    1. 在这里下载ez_setup.py并保存在C:\python34\scripts
    2. 运行C:\python34\scripts> python ez_setup.py
  5. 安装PIP
    1. 从这里下载get-pip.py并保存在C:\python34\scripts
    2. 运行C:\python34\scripts> python get-pip.py
  6. 安装LXML
    1. 从这里下载LXML 3.4.4 ,以获得您的Windows和PC体系结构的版本
    2. 运行EXE文件

我最近也遇到这个问题。 pip不能在.whl文件上工作。 而不是解决这个问题,我通过.exe文件安装它。 你可以从这里下载。请选择你的python的正确版本。 希望这可以帮到你。