简体   繁体   中英

Error using etree in lxml

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!!

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

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.

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/

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM