hhursev / recipe-scrapers

Python package for scraping recipes data
MIT License
1.6k stars 505 forks source link

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

Closed ghostiek closed 1 month ago

ghostiek commented 1 month ago

Installed the library on Python 3.10 and 3.12 on my Linux Mint installation, and keep getting the following message every time I simply import the library

from recipe_scrapers import scrape_me

Error message:

/home/ghostiek/PycharmProjects/appname/venv/bin/python /home/ghostiek/PycharmProjects/appname/src/Recipe.py 
Traceback (most recent call last):
  File "/home/ghostiek/PycharmProjects/appname/src/Recipe.py", line 3, in <module>
    from recipe_scrapers import scrape_me
  File "/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/recipe_scrapers/__init__.py", line 6, in <module>
    from ._abstract import AbstractScraper
  File "/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/recipe_scrapers/_abstract.py", line 13, in <module>
    from ._schemaorg import SchemaOrg
  File "/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/recipe_scrapers/_schemaorg.py", line 8, in <module>
    import extruct
  File "/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/extruct/__init__.py", line 1, in <module>
    from ._extruct import SYNTAXES, extract
  File "/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/extruct/_extruct.py", line 9, in <module>
    from extruct.dublincore import DublinCoreExtractor
  File "/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/extruct/dublincore.py", line 6, in <module>
    from extruct.utils import parse_html
  File "/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/extruct/utils.py", line 5, in <module>
    from extruct.xmldom import XmlDomHTMLParser
  File "/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/extruct/xmldom.py", line 9, in <module>
    from lxml.etree import (
ImportError: cannot import name '_ElementStringResult' from 'lxml.etree' (/home/ghostiek/PycharmProjects/appname/venv/lib/python3.12/site-packages/lxml/etree.cpython-312-x86_64-linux-gnu.so). Did you mean: '_ElementUnicodeResult'?
jayaddison commented 1 month ago

Hi @ghostiek - thanks for the bugreport; this seems to be the same issue as #1045.

There's a compatibility issue between one of the packages that recipe-scrapers uses, called extruct, and a library that it uses called lxml.

At the moment I'd recommend one of two options; either:

jayaddison commented 1 month ago

Closing as a duplicate of #1045.