How to install lxml?

Question:

The following error appears when i try pip install lxml

C:Program FilesPython311>pip install lxml
Collecting lxml
  Using cached lxml-4.9.1.tar.gz (3.4 MB)
  Preparing metadata (setup.py) ... done
Installing collected packages: lxml
  DEPRECATION: lxml is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for lxml ... error
  error: subprocess-exited-with-error

  × Running setup.py install for lxml did not run successfully.
  │ exit code: 1
  ╰─> [76 lines of output]
      Building lxml version 4.9.1.
      Building without Cython.
      Building against pre-built libxml2 andl libxslt libraries
      running install
      C:Program FilesPython311Libsite-packagessetuptoolscommandinstall.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating buildlib.win-amd64-cpython-311
      creating buildlib.win-amd64-cpython-311lxml
      copying srclxmlbuilder.py -> buildlib.win-amd64-cpython-311lxml
      copying srclxmlcssselect.py -> buildlib.win-amd64-cpython-311lxml
      copying srclxmldoctestcompare.py -> buildlib.win-amd64-cpython-311lxml
      copying srclxmlElementInclude.py -> buildlib.win-amd64-cpython-311lxml
      copying srclxmlpyclasslookup.py -> buildlib.win-amd64-cpython-311lxml
      copying srclxmlsax.py -> buildlib.win-amd64-cpython-311lxml
      copying srclxmlusedoctest.py -> buildlib.win-amd64-cpython-311lxml
      copying srclxml_elementpath.py -> buildlib.win-amd64-cpython-311lxml
      copying srclxml__init__.py -> buildlib.win-amd64-cpython-311lxml
      creating buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludes__init__.py -> buildlib.win-amd64-cpython-311lxmlincludes
      creating buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmlbuilder.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmlclean.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmldefs.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmldiff.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmlElementSoup.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmlformfill.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmlhtml5parser.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmlsoupparser.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtmlusedoctest.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtml_diffcommand.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtml_html5builder.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtml_setmixin.py -> buildlib.win-amd64-cpython-311lxmlhtml
      copying srclxmlhtml__init__.py -> buildlib.win-amd64-cpython-311lxmlhtml
      creating buildlib.win-amd64-cpython-311lxmlisoschematron
      copying srclxmlisoschematron__init__.py -> buildlib.win-amd64-cpython-311lxmlisoschematron
      copying srclxmletree.h -> buildlib.win-amd64-cpython-311lxml
      copying srclxmletree_api.h -> buildlib.win-amd64-cpython-311lxml
      copying srclxmllxml.etree.h -> buildlib.win-amd64-cpython-311lxml
      copying srclxmllxml.etree_api.h -> buildlib.win-amd64-cpython-311lxml
      copying srclxmlincludesc14n.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesconfig.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesdtdvalid.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesetreepublic.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludeshtmlparser.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesrelaxng.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesschematron.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludestree.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesuri.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesxinclude.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesxmlerror.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesxmlparser.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesxmlschema.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesxpath.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesxslt.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludes__init__.pxd -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludesetree_defs.h -> buildlib.win-amd64-cpython-311lxmlincludes
      copying srclxmlincludeslxml-version.h -> buildlib.win-amd64-cpython-311lxmlincludes
      creating buildlib.win-amd64-cpython-311lxmlisoschematronresources
      creating buildlib.win-amd64-cpython-311lxmlisoschematronresourcesrng
      copying srclxmlisoschematronresourcesrngiso-schematron.rng -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesrng
      creating buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsl
      copying srclxmlisoschematronresourcesxslRNG2Schtrn.xsl -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsl
      copying srclxmlisoschematronresourcesxslXSD2Schtrn.xsl -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsl
      creating buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsliso-schematron-xslt1
      copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_abstract_expand.xsl -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsliso-schematron-xslt1
      copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_dsdl_include.xsl -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsliso-schematron-xslt1
      copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_schematron_message.xsl -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsliso-schematron-xslt1
      copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_schematron_skeleton_for_xslt1.xsl -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsliso-schematron-xslt1
      copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_svrl_for_xslt1.xsl -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsliso-schematron-xslt1
      copying srclxmlisoschematronresourcesxsliso-schematron-xslt1readme.txt -> buildlib.win-amd64-cpython-311lxmlisoschematronresourcesxsliso-schematron-xslt1
      running build_ext
      building 'lxml.etree' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lxml

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

I try to run command : pip install lxml
and I expect to run this command without any specific error

Asked By: Mohamed Bilal

||

Answers:

First you can download the lxml-3.4.2-cp34-none-win_amd64.whl and try to install it, if you have something wrong try with the win_32 version:

Visit this link : How to install lxml on Windows

good luck

Answered By: aicha