ImportError: cannot import name 'etree' on Python 3.6
Asked Answered
I

6

36

I am getting error while running "from lxml import tree" on python3.6

>>> import lxml
>>> from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'etree'

The same working on python3.4, I have tried many things to troubleshoot as below but didn't success.

python -m pip uninstall lxml
python -m pip install lxml==3.6.0

pip install -t /usr/local/lib/python3.6/dist-packages lxml==3.6.0
Inseparable answered 21/11, 2018 at 6:50 Comment(2)
Possible duplicate of Receiving 'ImportError: cannot import name etree' when using lxml in Python on MacOsset
The same visible at python but while import it getting same errorInseparable
S
47

Just in case anybody has similar issue. I also encountered this problem using Python3.6. Just by uninstalling lxml and installing it again with pip the issue is resolved.

Signify answered 22/12, 2018 at 19:32 Comment(4)
Didn't work for me. Especially not in a lambda function environment.Git
I changed my lambda runtime from python3.8 to python3.6 and it magically workedGrappa
The system wide APT package was python-lxml , and the pip package was merely lxml in my case.Pinxit
sudo pip3 uninstall lxml and then pip3 install lxml worked for me.Dirtcheap
C
2

Got this working in Lambda with python 3.6

Turns out lxml wraps c libraries that are compiled for a certain processor architecture (I think)

Use precompiled binaries for lambda here: https://github.com/JFox/aws-lambda-lxml

Cayes answered 21/1, 2021 at 10:26 Comment(0)
E
2

I had the same problem in Python server with cPanel Here are the commands I typed in the terminal to solve the issue:

pip uninstall lxml
pip install lxml

Afterwards I stopped and then started the Python server.

Epode answered 8/6, 2023 at 14:9 Comment(0)
P
1

For Windows:

After having the same problem at the instance of my Windows 2019 server, Python 3.8 and Anaconda, I downloaded the corresponding whl package, installed it with

pip install lxml-4.6.3-cp38-cp38-win_amd64

It now works without problem.

Pratique answered 27/3, 2021 at 16:55 Comment(0)
A
0

I have the same issue when deploying an Azure python function using version 3.9. I redeployed with 3.6 in Azure an everything worked fine.

Acrylyl answered 21/9, 2021 at 20:53 Comment(0)
C
0

Had the same while running the code in VS code.For me I got it resolved by changing the interpreter in VS code from 32-bit to 64-bit.

Cilicia answered 4/10, 2021 at 10:14 Comment(1)
I suspect the architecture was not the difference that matters hare and there is some other difference between those two interpreters' environments.Jamaaljamaica

© 2022 - 2024 — McMap. All rights reserved.