繁体   English   中英

无法在 Python 3.7 中导入名称“etree”,我怎样才能让它工作?

[英]Cannot import name 'etree' in Python 3.7, how can I get this working?

我正在使用 Python,第 13 章完成自动化无聊的工作,但无法弄清楚如何让 python-docx 模块工作。 当我尝试导入它时ImportError: cannot import name 'etree' from 'lxml' (<path>,__init__.py) 尝试from lxml import etree也不起作用。 我已经在这几天了,刚刚安装了 Anaconda,其中包括 lxml 所需的 libxml2 和 libxslt,但仍然没有。 有任何想法吗? 我非常迷茫,整个过程涉及大约 4 或 5 个不同的文档,我无法理解其中的任何一个。

这是我尝试过的几个StackOverflow问题:

我还找到了一个.exe ,但它适用于 Python 2.7。

我在 Windows 10 上使用 Python 3.7 64 位。

除了上面的解决方案,我已经在两个不同的目录中卸载并重新安装了这些包,但无济于事。

好的 furas,谢谢你的提示,这里是 Traceback。

C:\Users\...>py
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>> from lxml import etree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'etree' from 'lxml' (C:\Users\...\AppData\Roaming\Python\Python37\site-packages\lxml\__init__.py)


**MY PERSONAL SOLUTION:**
After messing with this for three days I decided to uninstall every Python release I had on my PC and do a clean install. That was the only way for me to get it working, but it worked! No surprises there I think. I'm assuming there was a problem with how I had Python installed because I had two separate directories with different releases and pip was installing packages in a weird way. It doesn't make sense to me but the problem is solved on my end. I don't know if this will help anyone else.

也许您已经安装了 Anaconda 和 Python。 这种情况会导致 Python 脚本之间发生冲突。 解决方案是从 Python 安装位置删除 Python 脚本和包。 它可能在 C:\programfiles\Python(如果全局安装)或 %USER\AppData\Roaming\Python 上。

暂无
暂无

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

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