5

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!

Bamasdrey
  • 51
  • 1
  • 1
  • 3
  • python module `lxml` needs C/C++ library `libxml2` and `libxslt` which you have to install manually (not with `pip`) – furas Feb 17 '22 at 07: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 – furas Feb 17 '22 at 07: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` – furas Feb 17 '22 at 07: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. – Bamasdrey Feb 17 '22 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 – Bamasdrey Feb 17 '22 at 17:59
  • `VSC` may have installed own Python. As I remeber somewhere in VSC settings you can change `/full/path/to/python3.10` and it will also use `3.10`. If you run script in 3.10 with `print( sys.executable )` then you should get `/full/path/to/python3.10` – furas Feb 17 '22 at 18:25
  • @furas I changed that, but cygwin still uses a different version of python3 (3.6) for some reason, but it has my python version correct (3.10). Python is located at: `C:\cygwin64\bin\python C:\Users\Bamas\AppData\Local\Programs\Python\Python310\python.exe C:\Users\Bamas\AppData\Local\Microsoft\WindowsApps\python.exe` However python3 is located at: `C:\cygwin64\bin\python3 C:\Users\Bamas\AppData\Local\Microsoft\WindowsApps\python3.exe` – Bamasdrey Feb 17 '22 at 19:15
  • you can also try to use `c:\full\path\to\python3.10 -m cython ...` – furas Feb 17 '22 at 21:33

5 Answers5

8

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

JUNED MEMON
  • 81
  • 1
  • 4
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

0

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.

Ned Hulton
  • 477
  • 3
  • 12
  • 27
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.

0

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
aks
  • 1,019
  • 1
  • 9
  • 17