Menu

#17 "AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'prefix' " because lxml not installed

1.0
open
nobody
None
2023-04-20
2021-08-12
No

Hi,

I was receiving the error

self.ns_prefix_ = node.prefix
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'prefix'

when parsing an xml string using the generated python code. It was the identical error posted here

https://github.com/andrebrait/1g1r-romset-generator/issues/3

Here is the patch that was posted in response.

https://github.com/andrebrait/1g1r-romset-generator/commit/402ef60534ae4e25bd64eb066caf0f93dde84373

I ended up installing lxml and then the error went away. A possible fix is to make lxml a required package for installation in setup.py?

Mark Lai

Related

Tickets: #17

Discussion

  • Dave Kuhlman

    Dave Kuhlman - 2021-08-13

    Mark,

    Making Lxml a requirement sounds like a good idea to me.
    In generateds/setup.py, I already find the following, but I
    can't find any documentation on what it does.

    install_requires=[
            "six",
            "lxml",
            "requests>=2.21.0"
        ],
    

    Is that what you were suggesting?
    Or is there something more that I should do?

    Dave

     
    • SourceForgeMark

      SourceForgeMark - 2021-08-13

      Actually, I think my suggestion was poor! =)

      I think we can just remove the try import statement from the generated code
      i.e. changing

      try:
      from lxml import etree as etree_
      except ModulenotfoundExp_ :
      from xml.etree import ElementTree as etree_

      to just

      from lxml import etree as etree_

      We won't know what python environment the user is running the generated
      python script from so by forcing the lxml import the user will know that
      lxml is required. Perhaps this requirement to run generated python scripts
      can be added to the documentation somewhere also.

      On Fri, Aug 13, 2021 at 12:51 PM Dave Kuhlman dkuhlman@users.sourceforge.net wrote:

      Mark,

      Making Lxml a requirement sounds like a good idea to me.
      In generateds/setup.py, I already find the following, but I
      can't find any documentation on what it does.

      install_requires=
      "six",
      "lxml",
      "requests>=2.21.0"
      ,

      Is that what you were suggesting?
      Or is there something more that I should do?

      Dave

      Status: open
      Milestone: 1.0
      Created: Thu Aug 12, 2021 09:06 PM UTC by SourceForgeMark
      Last Updated: Thu Aug 12, 2021 09:06 PM UTC
      Owner: nobody

      Hi,

      I was receiving the error

      self.ns_prefix_ = node.prefix
      AttributeError: 'xml.etree.ElementTree.Element' object has no attribute
      'prefix'

      when parsing an xml string using the generated python code. It was the
      identical error posted here

      https://github.com/andrebrait/1g1r-romset-generator/issues/3

      Here is the patch that was posted in response.

      https://github.com/andrebrait/1g1r-romset-generator/commit/402ef60534ae4e25bd64eb066caf0f93dde84373

      I ended up installing lxml and then the error went away. A possible fix is
      to make lxml a required package for installation in setup.py?

      Mark Lai

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/generateds/tickets/17/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Tickets: #17

  • Dave Kuhlman

    Dave Kuhlman - 2021-08-17

    Mark,

    I've removed the try/except from around the import of lxml. I agree with you. That was a trap waiting to bite someone. I apologize that it was you.

    I worry that there might be someone out there who has distributed a module generated by gDS and who does not want to require all their users to install lxml. But, requiring lxml makes their code safer and they should do it for their own good and their users good, and tough love, etc.

    The new version (v. 2.39.4) is at SourceForge and PyPI.

    Thanks for the nudge on this.

    Dave

     

    Last edit: Dave Kuhlman 2021-08-17
  • Marco Bomben

    Marco Bomben - 2023-04-20

    Dear all,
    I am using generateDS since 2014 and it is a fantastic tool, thanks Dave!

    I have recently switched to 2.43.1 and I have the problem reported above:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/mbomben/work/python_scripts/make_plots.py", line 17, in mp
        plot.build(root)
      File "/Users/mbomben/work/python_scripts/root_multi_graph.py", line 2132, in build
        self.ns_prefix_ = node.prefix
    AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'prefix'
    

    I am using Python 3.10.10 packaged by conda-forge and lxml is installed. I attach here the xsd I am using and a file to test the class produced.

    Any help will be greatly appreciated.

    Many thanks in advance and best regards,
    Marco Bomben

     

    Last edit: Marco Bomben 2023-04-20

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.