jdum / odfdo

python library for OpenDocument format (ODF)
Apache License 2.0
58 stars 11 forks source link

ImportError: cannot import name '_ElementStringResult' from 'lxml.etree' #39

Closed derby-vv closed 7 months ago

derby-vv commented 7 months ago

windows 11

Traceback (most recent call last):
  File "run_tests.py", line 3, in <module>
    from external.tests import main_test
  File "main_test.py", line 6, in <module>
    from odsparsator import odsparsator
  File "\Lib\site-packages\odsparsator\odsparsator.py", line 21, in <module>
    from odfdo import Document, Element
  File "\Lib\site-packages\odfdo\__init__.py", line 138, in <module>
    from .bookmark import Bookmark, BookmarkEnd, BookmarkStart
  File "\Lib\site-packages\odfdo\bookmark.py", line 27, in <module>
    from .element import Element, PropDef, register_element_class
  File "\Lib\site-packages\odfdo\element.py", line 39, in <module>
    from lxml.etree import (
ImportError: cannot import name '_ElementStringResult' from 'lxml.etree' (\Lib\site-packages\lxml\etree.cp311-win_amd64.pyd)
python -m pip uninstall lxml
Found existing installation: lxml 5.1.1
Uninstalling lxml-5.1.1:
  Would remove:
    \lib\site-packages\lxml-5.1.1.dist-info\*
    \lib\site-packages\lxml\*
Proceed (Y/n)? Y
  Successfully uninstalled lxml-5.1.1

It doesn't help

python -m pip install lxml==3.1.2                             
Collecting lxml==3.1.2
  Downloading lxml-3.1.2.tar.gz (3.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 7.8 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: lxml
  Building wheel for lxml (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [83 lines of output]
      Building lxml version 3.1.2.
      Building without Cython.
      ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
      ** make sure the development packages of libxml2 and libxslt are installed **

(some more useless output and...)

...and finally installing older version of lxml stucks with error

      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.39.33519\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lxml
  Running setup.py clean for lxml
Failed to build lxml
ERROR: Could not build wheels for lxml, which is required to install pyproject.toml-based projects

Tested on python --version Python 3.11.6

Does anyone worked on windows with this library? What lxml version should I try?

derby-vv commented 7 months ago

To prevent misunderstood, code fails on simple import statement.

jdum commented 7 months ago

Hi, you find a bug (lxml change between 5.1.0 and 5.1.1). Quick way to solve the problem: update to the last odfdo package of today (v3.7.6) pip install -U odfdo

Detail:

if you prefer to not resinstall odfdo, just doing this should also work: pip install lxml==5.1.0

I'll try to make a more long term fix permitting wider range of lxml version in next releases

dgtlmoon commented 7 months ago

Hi guys, found you in google :-) if this helps this is how we solved it https://github.com/dgtlmoon/changedetection.io/pull/2313/files

jdum commented 7 months ago

Hi, thanks, we applied quite the same fix: https://github.com/jdum/odfdo/commit/d813854dee57f95abca2a75e67c805dce3de8487