Error using etree in lxml
Asked Answered
B

7

10

I want to use xpath in python . I tried

import xml.etree.ElementTree as ET

Since this library has limited usage I had to use lxml after a long session of search on google. I had several problems during installation and finally i installed lxml but when i use

from lxml import etree

it throws back an error as below. could you please tell me the solution to this problem!!!

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from lxml import etree
ImportError: DLL load failed: %1 is not a valid Win32 application.

Can any1 tell me what the problem would be?? Thanks for assistance!!

Biblio answered 30/4, 2013 at 9:4 Comment(3)
Seems that you have a broken lxml library. Have you tried reinstalling it?Eer
@BasicWolf I did reinstall lxml several times..I downloaded the .exe file and ran it..It completed the installation but still it throws an error!!Biblio
@BasicWolf Is it the issue of 32bit and 64bit systems?? because i read in one the answers that it has some compatibility issues with 64bit computers...Does that bug still exist or are there any change logs? thanksBiblio
S
18

I know that's late to say this... But may help someone someday..

I use the following code to solve the exact same problem here

python -m pip uninstall lxml
python -m pip install lxml==3.6.0
Sandy answered 22/12, 2016 at 18:19 Comment(0)
W
9

I solved this by downloading the 64-bit version of lxml here:

https://pypi.python.org/pypi/lxml/3.4.1

lxml-3.4.1.win-amd64-py2.7.exe

It's the only one that worked to solve the win32 error. You might want to destroy the old version of lxml before you do this.

Washerwoman answered 28/11, 2014 at 11:10 Comment(1)
This was my problem in reverse. I have python 32bit but had installed amd64 lxml. So just a heads up to everyone: the windows binary lxml installer doesn't check for matching 32/64 bitness.Anguine
A
1

Since you mentioned you had to fight with lxml to get it to install, it's hard to say where in that process this error might've cropped up.

Are you installing lxml to your default installation of Python or somewhere else? If you're installing to your default installation, one of the .exe options from https://pypi.python.org/pypi/lxml/3.2.0 might be your best bet. I, too, have had to fight with lxml in some cases but those .exe options are the easiest way I've found.

If you are trying to install lxml to some other Python installation, I'd suggest using a .egg file along with setup tools. Sadly, the most recent .egg files I can find for lxml are for 2.3 but you can get them here https://botbot.me/freenode/kivy/

Avens answered 1/5, 2013 at 2:49 Comment(0)
N
1

I got the same problem. Essentially, my operating system is 64 Bit and my python is 64 bit too. But the tools and site packages I had installed were 32 bit except for Ixml which was 64 bit. So, I installed Ixml 32 bit version from the below link and it worked fine for me.

https://pypi.python.org/pypi/lxml/

I believe the system is looking for a 32 bit implementation of Ixml but it has found 64 bit instead. I hope this solves the problem.

Nne answered 12/4, 2014 at 21:40 Comment(0)
F
1

I had the same problem. The Win32 part was confusing at first, since I am running a 64-bit system. The solution, perhaps because the actual python version used 32-bit components, was simply to uninstall the old version of lxml and install the 32-bit version, here: https://pypi.python.org/pypi/lxml/3.4.1#downloads

Farmyard answered 13/4, 2016 at 18:22 Comment(0)
G
0

Just adding this just in case someone in similar situation get benefited. Though my Python & the libraries required for Scrapy were 32bit installation i was still hitting into this issue. After i upgraded my Python to next version, the issue got resolved automatically.

Glialentn answered 27/6, 2017 at 10:17 Comment(0)
M
0

Deleting the library folders related to lxml in the Python site-package ( ~/Library/Python/3.8/lib/python/site-packages/lxml in Linux/MacOS ) followed by the following command helped:

python -m pip install lxml

Version 3.6.0 from the previous command no longer works. The above command will install the latest compatible version which was 4.8.x when I installed.

Mosasaur answered 22/4, 2022 at 20:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.