10

I am attempting to use pip to install lxml. I have Windows 11 and Python version python-3.10.2-amd64. I am using Visual Studio Code (VSC) as well. I realized I needed lxml from this error message in my VSC terminal:

Traceback (most recent call last):
File "Vegas.py", line 13, in <module>
soup = BeautifulSoup(html_text, 'lxml')
File "/usr/lib/python3.6/site-packages/bs4/__init__.py", line 248, in 
__init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you 
requested: lxml. Do you need to install a parser library?

From there, I tried to install lxml by using the command in the VSC terminal:

pip install lxml

And I got this error message:

Collecting lxml
  Using cached lxml-4.7.1.tar.gz (3.2 MB)
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3.6 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-xgwntbxb/lxml_73c33ff5c1614a6da59bbd9f3017fa5c/setup.py'"'"'; __file__='"'"'/tmp/pip-install-xgwntbxb/lxml_73c33ff5c1614a6da59bbd9f3017fa5c/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ezhmqybu
       cwd: /tmp/pip-install-xgwntbxb/lxml_73c33ff5c1614a6da59bbd9f3017fa5c/
  Complete output (3 lines):
  Building lxml version 4.7.1.
  Building without Cython.
  Error: Please make sure the libxml2 and libxslt development packages are installed.
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/84/74/4a97db45381316cd6e7d4b1eb707d7f60d38cb2985b5dfd7251a340404da/lxml-4.7.1.tar.gz#sha256=a1613838aa6b89af4ba10a0f3a972836128801ed008078f8c1244e65958f1b24 (from https://pypi.org/simple/lxml/) (requires-python:>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, != 3.4.*). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Using cached lxml-4.6.5.tar.gz (3.2 MB)

So I went to this website to download libmxl2 and libxslt: https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml. After downloading the lxml‑4.7.1‑cp310‑cp310‑win_amd64.whl version (since it matched my python version) I tried using the following command in the windows command prompt:

pip install lxml-4.7.1-cp310-cp310-win_amd64.whl

And I got this result:

lxml is already installed with the same version as the provided wheel. 
Use --force-reinstall to force an installation of the wheel.

So then I did the same command but added the --force-reinstall and it said it successfully installed lxml-4.7.1. Then I went back to the VSC terminal, ran "pip install lxml" and got the same error message as I did before. So I tried the "pip install lxml-4.7.1-cp310-cp310-win_amd64.whl" command in the VSC terminal and got this error:

ERROR: lxml-4.7.1-cp310-cp310-win_amd64.whl is not a supported wheel on this platform.

Then I thought that I should try the win32 version since I have an Intel processor. So I run this command in the command prompt:

pip install lxml-4.7.1-cp310-cp310-win32.whl

And I get this error message:

ERROR: lxml-4.7.1-cp310-cp310-win32.whl is not a supported wheel on this platform.

So I'm at a loss. Any help is greatly appreciated!

8
  • python module lxml needs C/C++ library libxml2 and libxslt which you have to install manually (not with pip) Commented Feb 17, 2022 at 7:00
  • Python 3.10 is very new version and some modules may not work with this version (authors may need time to create modules for this version). Better wait few months and use 3.9 or 3.8 Commented Feb 17, 2022 at 7:04
  • 1
    your error messages shows that you use Python 3.6, not Python 3.10. See in errors lines command: /usr/bin/python3.6 and File "/usr/lib/python3.6/.... Better check what version you really use - pip -V and python -V - because it seems you downloaded wrong lxml Commented Feb 17, 2022 at 7:06
  • @furas Thank you! I only have python 3.10 installed, however, I use cygwin with Visual Studio Code. And when I installed cygwin, its default python version was 3.6. So I had to go through and change the python version in cygwin to 3.10. Commented Feb 17, 2022 at 17:48
  • @furas I am running into a situation where my pip is also using the version of python that cygwin was using. When I run "pip -V" in the VSC terminal, it says 3.6, but in the command prompt it says 3.10 when I run the same command Commented Feb 17, 2022 at 17:59

6 Answers 6

11

I am using windows 11 and python 3.11 so for the easy solution first I downloaded the latest 'lxml-4.9.0-cp311-cp311-win_amd64.whl' from the https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

Then copied it to my user folder which is "C:\Users\memon"

And then run this command from the terminal:

pip install lxml-4.9.0-cp311-cp311-win_amd64.whl

And it successfully installed 'lxml' on my windows 11 without any errors.

Previously I was facing 'C++ 14.0 or greater is required' error for the same 'lxml' install which I resolved with this thread: https://stackoverflow.com/a/64262038/14957324

Sign up to request clarification or add additional context in comments.

3 Comments

This worked for me. I'm also using Windows 11 and Python 3.11
You should 'cd' to the folder where you have .whl file downloaded in the terminal before executing the command mentioned above.
The link is no longer available; but just found out you can retrieve the latest file in PIP official documents: pypi.org/project/lxml/#files
1

The solution provided by JUNED MEMON above worked for me.

pip install lxml-4.9.0-cp311-cp311-win_amd64.whl

I discovered after much misery that "p311" indicates python version 3.11 and that the download must exactly match the python version in use.

Comments

1

This worked for me on mac

pip install https://github.com/lxml/lxml/releases/download/lxml-4.9.2/lxml-4.9.2-cp311-cp311-macosx_10_15_universal2.whl

Comments

0

Try with the last wheels on https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml corresponding to your 3.10 version. It worked for me

Comments

0

I was also facing the same problem. Later what i did is:

1st step: in cmd panel i did "pip install numpy" (you can skip if it is already installed".

2nd step: in cmd panel I did "pip install mkl"

3rd step: i downloaded "lxml-4.9.0-cp311-cp311-win_amd64.whl" this file from website: https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml. The reason for choosing this file is my python version is 3.11.00 and window is 64 bytes.

4th step: i then copied the "lxml-4.9.0-cp311-cp311-win_amd64.whl" file to "documents" folder from download folder

5th step: in cmd panel i typed "cd documents" to navigate to documents folder(where i have just stored the file "lxml-4.9.0-cp311-cp311-win_amd64.whl").

6th step: then i run pip install lxml-4.9.0-cp311-cp311-win_amd64.whl (in your case replace "lxml-4.9.0-cp311-cp311-win_amd64.whl" by the file name you downloaded) then finally lxml file is installed.

Actually i was trying to install "pytrends". for that lxml was required so after installing lxml i then installed pytrends using command "pip install pytrends". I hope this will work for you.

Comments

0

I had the exact same problem and lost a lot of time on it. The only way for me to solve it was a bit brutal. I unistalled everything and reinstalled the last stable version of python from the website.

Make sure to add it to the PATH before installation. I was able to install lxml and many other packages with which I had problems using pip

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.