0

I have used lxml's etree class successfully in 32-bit Python 3.2 using from lxml import etree, but I just installed it for 64-bit Python 3.5 using pip install lxml, and PyCharm calls etree an unresolved reference. PyCharm's interpreter settings window tells me that I am using version 3.2.3 of lxml in Python 3.2, and version 3.7.2 in Python 3.5.

I rely on XML parsing extensively in my scripts. How can I import etree from the latest version of lxml, or is there something else I'm supposed to do to get similar functionality from that module?

This question is a duplicate of one posted in April of 2016, but that question and similar ones were never answered. If I missed a question that had as answer, I would appreciate a link to that question.

Thank you very much.

EDIT: It appears that lxml does work with Python 3.5! After Dragon asked if I had actually tested it in Python or was merely relying on PyCharm flagging etree as unresolved, I tried I was merely relying on PyCharm. I tried this script:

from lxml import etree

if __name__=='__main__':
    print ("This is a print statement.")

    try:
        x = etree.fromstring("This is not XML")
    except Exception as ex:
        print (str(ex))

The output of this was:

C:\Python35\python.exe C:/Misc/lxmltest.py
This is a print statement.
Start tag expected, '<' not found, line 1, column 1 (<string>, line 1)

Process finished with exit code 0

I was expecting an unresolved reference error. Instead, the error message shows that etree.fromstring() was successfully called.

Many thanks to Dragon for his (her?) help

ROBERT RICHARDSON
  • 2,077
  • 4
  • 24
  • 57
  • Which OS? Do you get error messages from running the Python code as well as PyCharm warning you? What, exactly, are these error messages? Have you tried downgrading? `pip uninstall lxml`; `pip install lxml==2.3` Try working in a virtualenv to isolate yourself from any brokenness that your default python install might have? Good luck -- diagnosing these sorts of issues can be a complete nightmare! – Dragon Feb 15 '17 at 12:39
  • Thanks very much for your response. Being primarily a C# developer, I was assuming that PyCharm knew everything there is to know about every module and class I use. That appears to be false. I wrote a little test program, and the durn thing worked! I'll edit the original post to show my test. – ROBERT RICHARDSON Feb 15 '17 at 16:48
  • 1
    Quickly searching around suggests https://stackoverflow.com/questions/11725519/pycharm-shows-unresolved-references-error-for-valid-code might help fix the underlying problem. – Dragon Feb 16 '17 at 00:05

0 Answers0