简体   繁体   English

在 lxml 中使用 etree 时出错

[英]Error using etree in lxml

I want to use xpath in python. I tried我想在python中使用xpath。我试过了

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.由于这个库的使用有限,我在谷歌上搜索了 session 之后不得不使用 lxml。 I had several problems during installation and finally i installed lxml but when i use我在安装过程中遇到了几个问题,最后我安装了 lxml 但是当我使用

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: 我在这里通过下载64位版本的lxml来解决这个问题:

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

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

It's the only one that worked to solve the win32 error. 它是唯一一个解决win32错误的方法。 You might want to destroy the old version of lxml before you do this. 在执行此操作之前,您可能希望销毁旧版本的lxml。

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. 既然你提到你必须与lxml对抗才能安装它,很难说在这个过程中这个错误可能会出现在哪里。

Are you installing lxml to your default installation of Python or somewhere else? 您是否正在将lxml安装到Python的默认安装或其他位置? 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. 如果您要安装到默认安装, https: //pypi.python.org/pypi/lxml/3.2.0中的一个.exe选项可能是您最好的选择。 I, too, have had to fight with lxml in some cases but those .exe options are the easiest way I've found. 在某些情况下,我也不得不与lxml战斗,但那些.exe选项是我发现的最简单的方法。

If you are trying to install lxml to some other Python installation, I'd suggest using a .egg file along with setup tools. 如果您尝试将lxml安装到其他Python安装中,我建议使用.egg文件和设置工具。 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/ 可悲的是,我能为lxml找到的最新.egg文件是2.3,但你可以在这里得到它们https://botbot.me/freenode/kivy/

I got the same problem. 我遇到了同样的问题。 Essentially, my operating system is 64 Bit and my python is 64 bit too. 基本上,我的操作系统是64位,我的python也是64位。 But the tools and site packages I had installed were 32 bit except for Ixml which was 64 bit. 但我安装的工具和站点包是32位,除了Ixml是64位。 So, I installed Ixml 32 bit version from the below link and it worked fine for me. 所以,我从下面的链接安装了Ixml 32位版本,它对我来说很好。

https://pypi.python.org/pypi/lxml/ 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. 我相信系统正在寻找Ixml的32位实现,但它找到了64位。 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. Win32部分起初很混乱,因为我运行的是64位系统。 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 解决方案,也许是因为实际的python版本使用32位组件,只是卸载旧版本的lxml并安装32位版本,在这里: https//pypi.python.org/pypi/lxml/3.4。 1个#下载

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. 虽然我的Python和Scrapy所需的库是32位安装,但我仍然遇到了这个问题。 After i upgraded my Python to next version, the issue got resolved automatically. 在我将Python升级到下一版本后,问题自动得到解决。

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 site-package中与lxml相关的库文件夹( ~/Library/Python/3.8/lib/python/site-packages/lxml in Linux/MacOS ),然后执行以下命令有帮助:

python -m pip install lxml

Version 3.6.0 from the previous command no longer works.先前命令的版本3.6.0不再有效。 The above command will install the latest compatible version which was 4.8.x when I installed.上面的命令将安装最新的兼容版本,我安装时是4.8.x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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