Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

python - How to install lxml on Windows

I'm trying to install lmxl on my Windows 8.1 laptop with Python 3.4 and failing miserably.

First off, I tried the simple and obvious solution: pip install lxml. However, this didn't work. Here's what it said:

Downloading/unpacking lxml
  Running setup.py (path:C:UsersCARTE_~1AppDataLocalTemppip_build_carte_000lxmlsetup.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,
operable program or batch file.
"
    ** make sure the development packages of libxml2 and libxslt are installed **

    Using build configuration of libxslt
    C:Python34libdistutilsdist.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,
operable program or batch file.
"
    ** make sure the development packages of libxml2 and libxslt are installed **

    Using build configuration of libxslt
    building 'lxml.etree' extension
    C:Python34libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    error: Unable to find vcvarsall.bat
    Complete output from command C:Python34python.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('
', '
'), __file__, 'exec'))" install --record C:UsersCARTE_~1AppDataLocalTemppip-l8vvrv9g-recordinstall-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,
operable program or batch file.
"

** 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 buildlib.win32-3.4

creating buildlib.win32-3.4lxml

copying srclxmluilder.py -> buildlib.win32-3.4lxml

copying srclxmlcssselect.py -> buildlib.win32-3.4lxml

copying srclxmldoctestcompare.py -> buildlib.win32-3.4lxml

copying srclxmlElementInclude.py -> buildlib.win32-3.4lxml

copying srclxmlpyclasslookup.py -> buildlib.win32-3.4lxml

copying srclxmlsax.py -> buildlib.win32-3.4lxml

copying srclxmlusedoctest.py -> buildlib.win32-3.4lxml

copying srclxml\_elementpath.py -> buildlib.win32-3.4lxml

copying srclxml\__init__.py -> buildlib.win32-3.4lxml

creating buildlib.win32-3.4lxmlincludes

copying srclxmlincludes\__init__.py -> buildlib.win32-3.4lxmlincludes

creating buildlib.win32-3.4lxmlhtml

copying srclxmlhtmluilder.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtmlclean.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtmldefs.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtmldiff.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtmlElementSoup.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtmlformfill.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtmlhtml5parser.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtmlsoupparser.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtmlusedoctest.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtml\_diffcommand.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtml\_html5builder.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtml\_setmixin.py -> buildlib.win32-3.4lxmlhtml

copying srclxmlhtml\__init__.py -> buildlib.win32-3.4lxmlhtml

creating buildlib.win32-3.4lxmlisoschematron

copying srclxmlisoschematron\__init__.py -> buildlib.win32-3.4lxmlisoschematron

copying srclxmllxml.etree.h -> buildlib.win32-3.4lxml

copying srclxmllxml.etree_api.h -> buildlib.win32-3.4lxml

copying srclxmlincludesc14n.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesconfig.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesdtdvalid.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesetreepublic.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludeshtmlparser.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludes
elaxng.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesschematron.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesree.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesuri.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesxinclude.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesxmlerror.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesxmlparser.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesxmlschema.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesxpath.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesxslt.pxd -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludesetree_defs.h -> buildlib.win32-3.4lxmlincludes

copying srclxmlincludeslxml-version.h -> buildlib.win32-3.4lxmlincludes

creating buildlib.win32-3.4lxmlisoschematron
esources

creating buildlib.win32-3.4lxmlisoschematron
esources
ng

copying srclxmlisoschematron
esources
ngiso-schematron.rng -> buildlib.win32-3.4lxmlisoschematron
esources
ng

creating buildlib.win32-3.4lxmlisoschematron
esourcesxsl

copying srclxmlisoschematron
esourcesxslRNG2Schtrn.xsl -> buildlib.win32-3.4lxmlisoschematron
esourcesxsl

copying srclxmlisoschematron
esourcesxslXSD2Schtrn.xsl -> buildlib.win32-3.4lxmlisoschematron
esourcesxsl

creating buildlib.win32-3.4lxmlisoschematron
esourcesxsliso-schematron-xslt1

copying srclxmlisoschematron
esourcesxsliso-schematron-xslt1iso_abstract_expand.xsl -> buildlib.win32-3.4lxmlisoschematron
esourcesxsliso-schematron-xslt1

copying srclxmlisoschematron
esourcesxsliso-schematron-xslt1iso_dsdl_include.xsl -> buildlib.win32-3.4lxmlisoschematron
esourcesxsliso-schematron-xslt1

copying srclxmlisoschematron
esourcesxsliso-schematron-xslt1iso_schematron_message.xsl -> buildlib.win32-3.4lxmlisoschematron
esourcesxsliso-schematron-xslt1

copying srclxmlisoschematron
esourcesxsliso-schematron-xslt1iso_schematron_skeleton_for_xslt1.xsl -> buildlib.win32-3.4lxmlisoschematron
esourcesxsliso-schematron-xslt1

copying srclxmlisoschematron
esourcesxsliso-schematron-xslt1iso_svrl_for_xslt1.xsl -> buildlib.win32-3.4lxmlisoschematron
esourcesxsliso-schematron-xslt1

copying srclxmlisoschematron
esourcesxsliso-schematron-xslt1
eadme.txt -> buildlib.win32-3.4lxmlisoschematron
esourcesxsliso-schematron-xslt1

running build_ext

building 'lxml.etree' extension

C:Python34libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'

  warnings.warn(msg)

error: Unable to find vcvarsall.bat

----------------------------------------
Cleaning up...
Command C:Python34python.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('
', '
'), __file__, 'exec'))" install --record C:UsersCARTE_~1AppDataLocalTemppip-l8vvrv9g-recordinstall-record.txt --single-version-externally-managed --compile failed with error code 1 in C:UsersCARTE_~1AppDataLocalTemppip_build_carte_000lxml
Storing debug log for failure in C:Userscarte_000pippip.log

So then I looked on this great and helpful thing called The Internet and a lot of people have the same error of needing libxml2 and libxlst. They recommend a guy called Christoph Gohlke's page where he provides some sort of binary thingy for a bunch of packages. You can find it here (quicklink to the lxml part).

So after I gave up on trying to find libxml2 and libxslt for pip, I decided to go there, and found an absolute ton of downloads. I know I need a 64-bit one, but I have no idea which "cp" I need.

So an answer either giving me a solution on the pip method or the Gohlke index method would be great.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Or you can also go to Christoph's Gohlke's Python page and then download the right lxml file. (Generally since I use python 3.4 and I have a windows, I download the lxml-3.4.4-cp34-none-win32.whl)

Go to the folder it is in. Click in the background (so nothing is selected), then leftshift + rightclick at the same time and click on open command window. Then type C:/Python34/Scripts/pip install "NAME OF THE FILE YOU JUST DOWNLOADED.whl"

In this case it would be C:/Python34/Scripts/pip install "lxml-3.4.4-cp34-none-win32.whl"

Now hit enter. This worked well for me, and after you type the quote you can also press tab and it should fill the right one for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...