Reputation: 91
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!
Upvotes: 9
Views: 35298
Reputation: 1
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
Upvotes: 0
Reputation: 1029
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
Upvotes: 1
Reputation: 1
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.
Upvotes: 0
Reputation: 678
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.
Upvotes: 1
Reputation: 111
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
Upvotes: 11
Reputation: 1
Try with the last wheels on https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml corresponding to your 3.10 version. It worked for me
Upvotes: 0