I'm working through Automate the Boring Stuff with Python, Chapter 13, and can't figure out how to get the python-docx module working. When I try to import it ImportError: cannot import name 'etree' from 'lxml' (<path>,__init__.py)
. Trying from lxml import etree
doesn't work either. I've been at this for days, just installed Anaconda which includes libxml2 and libxslt which are required for lxml and still nothing. Any ideas? I'm extremely lost, there's about 4 or 5 different docs involved with this entire process and I can't make sense of any of it.
Here's a couple of StackOverflow questions I've tried bits and pieces from:
- Installing lxml, libxml2, libxslt for Python 3.5 on Windows 10 - This is where I decided to install Anaconda thanks to furas's answer
- LXML: Cannot import etree - From here I tried installing different wheels. I already had
lxml
installed frompip
so it didn't matter anyway, but I learned a bit about wheels so that was good.
I also found a .exe
but it was for Python 2.7.
I'm using Python 3.7 64 bit on Windows 10.
Besides the solutions above I have uninstalled and reinstalled these packages in two different directories to no avail.
Okay furas, thank you for the tip, here is the 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.
pip install lxml
? Some other way?conda install
? – Stramoniumpip install lxml
orpip install --upgrade lxml
in a Conda prompt(?). Just a couple days ago I upgraded withpython -m pip install --upgrade lxml
from a Powershell prompt andfrom lxml import etree
works fine (albeit I don't have Anaconda installed on this computer). – Consequentlypip install lxml
, and I also used-t <directory>
because I had some issues with a different module not installing in the rightsite packages
directory, then when I tried Anaconda I usedconda install
@Consequently I just tried both of those, lxml is up to date. I can importlxml
but notetree
. – Sinhalese