26

After additional exploration, I found a solution to installing lxml with pip and wheel. Additional comments on approach welcomed.

I'm finding the existing Python documentation for Linux distributions excellent. For Windows... not so much. I've configured my Linux system fine but I need some help getting a Windows 8.1 tablet ready as well.

My project requires the lxml module for Python 3.4. I've found many tutorials on how to install lxml but each has failed.

https://docs.python.org/3/installing/ I've downloaded the "get-pip.py" and successfully ran it from the Windows cmd line with the result:

Requirement already up-to-date: pip in c:\python34\lib\site-packages 

So I don't think that I have a "pip" problem. From there I've run the following from the Windows cmd line:

python -m pip install lxml 

A long list of commands scroll through but there are a couple of lines that appear to be errors that I'm unable to resolve.

 ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n" ** make sure the development packages of libxml2 and libxslt are installed ** 

and

Failed building wheel for lxml 

And the last part, all in red

Command "C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Owner\\AppData\\Local\\Temp\\pip-build-ya3n6wkd\\lxml\\setup.py';exec(compi le(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Owner\AppData\Local\Temp\pip-ytybzl9l-r ecord\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Owner\AppData\Local\Temp\pip-build-ya3n6wkd\lxml 

Any assistance in understanding how this should work, or what I'm doing wrong would be greatly appreciated.

4
  • he, he. not gonna make any great suggestions, but I had some unpleasantness pip-ing libxml on Ubuntu with Chef. Or, not installing it, rather as I only needed it for some unit testing, which I could do elsewhere. What I did find was that lxml, on Linux, has non-PIP dependencies apparently. Yeah, I know, Windows, not Linux, but maybe you'll see something of interest @ stackoverflow.com/questions/6504810/… Is there a prereq you need to install manually? Commented May 27, 2015 at 21:07
  • @JLPeyret - There's no prerequisites except getting my laptop to work PyCharm with lxml. I just need to get the environment to work. I don't know why it's such a pain to get a module installed on Windows. If there's a better approach, I'll try anything. Commented May 27, 2015 at 21:29
  • What I meant is that lxml, on Ubuntu, apparently needs to find some packages installed that would be put in via apt-get, not pip. So you can bang your head into pip all you want in that case, it will blow up if it doesn't have the right files from those other packages. I was just pointing the possibility of there being a similar pre-requisite install for lxml on Windows. Which you then presumably need to install an .exe or .msi file for in advance of running pip. On Ubuntu at least, it's not like it was at all obvious from lxml's pip errors which were all over the place. Commented May 27, 2015 at 22:32
  • See also pypi.python.org/pypi/lxml/3.4.0 and lxml.de/installation.html notes about using binaries. Commented May 27, 2015 at 22:37

4 Answers 4

63

I was able to fix the installation with the following steps. I hope others find this helpful.

My installation of "pip" was working fine before the problem. I went to the Windows command line and made sure that "wheel" was installed.

C:\Python34>python -m pip install wheel Requirement already satisfied (use --upgrade to upgrade): wheel in c:\python34\lib\site-packages 

After that I downloaded the lxml file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml and placed it in my python directory "C:\Python34"

In that directory I ran the following:

C:\Python34>python -m pip install lxml-3.4.4-cp34-none-win32.whl 

The results were:

Processing c:\python34\lxml-3.4.4-cp34-none-win32.whl Installing collected packages: lxml Successfully installed lxml-3.4.4 

I opened PyCharm and lxml module was available. I was able to execute the code without problem.

What I learned (though this may be corrected by others more knowledgeable)

  1. Need to install the desired module (as a "*.whl" file) using pip and wheel.
  2. Using Dropbox to share a code folder with different PyCharm installations causes confusion for the "workspace.xml" file. The two computers kept writing over each other, messing up the installation paths.

Hope this helps.

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

4 Comments

Thanks a toooonnnn!! ....I was working on solving this for the last 5 hrs...tried installing lxml with pip...did not work...then tried its dependencies libxml2 and libxslt individually...did not work...tried installing visual c++ for libxml2...that did not work too...in short none of the googled solution worked, save for this. this is the perfect solution and went exactly as per the steps written above.
Uninstalling Python 3.5.2 and installing Python 3.4.4 worked for me. Didn't even have this issue in the cmd prompt after doing this. lxml installed right away.
Manually install lxml is God-like solution, saved me hours!
When trying to install the wheel, I got an error (lxml-4.5.1-cp38-cp38-win_amd64.whl is not a supported wheel on this platform.) This site had instructions for how to get around the issue (Google Translate for the win!): blog.csdn.net/ourjaycn/article/details/106718952 By renaming the wheel to lxml-4.5.1-cp38-cp38m-win_amd64.whl (note the 'm' in "cp38m"), it installed successfully.
5

My situation was a lot like this. I have Python 3.4 installed on my Laptop for work, and we're in a tight security, so I can't just install 3.5 without getting system admin to do it.

So I hit up Python Extension site here:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

Pulled the wheel file for lxml that matched my specs:

lxml-3.6.4-cp34-cp34m-win_amd64.whl 

And then just typed:

pip install lxml-3.6.4-cp34-cp34m-win_amd64.whl 

And it installed right away.

Comments

0

I started working with lxml a little while ago, when there was a need to parse some html files. I somehow installed it and then after some time I lost the installation because of PC format.

Installing lxml on Windows from the available binaries/wheels is quite easy. The below link has the binaries/wheels in case you need them.

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

After downloading the wheel file as per your Windows you can issue the below command pip install <pathtoyourdownloadedwheelfile>

And In case you are using git-sdk-win32 for Windows, You can first search the libxml2-devel,libxml2-python and libxslt-devel, libxslt-python using pacman by issuing the below command.

pacman -Ss libxml2

and

pacman -Ss libxslt

then you can install lxml using the below command

pip install lxml It might fail to build the wheel(as it did for me) but will install lxml using the setup.py

I simply have started loving this git-win32-sdk. It helps me work on my Windows with what I have learnt on Linux.

https://github.com/git-for-windows/build-extra/releases

Comments

0

This issue appears to be fixed as of lxml version 4.2.5.

If you're still getting this error and you're specifying a specific version of lxml in a requirements file, try updating the requirements file to specify lxml version 4.2.5 or above.

I had this error with lxml 4.2.1. But it was fixed when I changed the requirement to lxml 4.2.5.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.