I can't import xml.dom.minidom in PyCharm. What could I Try?

♀尐吖头ヾ 提交于 2020-06-08 19:17:08

问题


I'm trying to import xml.dom.minidom but pycharm doesn't find it, altough it finds xml.entree / xml.parser / xml.sax.

The rest of the standart libraries work all fine. The xml file (beispiel.xml) shouldn't be the problem, because it hasn't "xml" in the name.


    from xml.dom import minidom

    document = minidom.parse("beispiel.xml")

    wanted_info = input("Which prduct do you want to see?")

    product_list = document.getElementsByTagName(wanted_info)

    for product in product_list:

        for value in product.childNodes:
            if value.nodeType == minidom.Node.ELEMENT_NODE:
                print(value.tagName + ":" + value.firstChild.data)
        print("\n")

I'm not shure, what it could be. It could be, because i have installed python in D:... and pycharm in C:... but i dont think that's the problem.


回答1:


I faced the same problem after upgrading to 2020.1. The problem is already reported in the Pycharm issue tracker.

There they propose the following workaround until the issue is fixed:

Replace xml directory in <INSTALLATION_FOLDER>\plugins\python(-ce)\helpers\typeshed\stdlib\2and3\ with xml from https://github.com/python/typeshed/tree/master/stdlib/2and3/xml

On my machine this solved the problem.




回答2:


My recommendation is to just put the following around the imports until Pycharm fixes the bug.

# noinspection PyUnresolvedReferences
from xml.dom.minidom import Document
# noinspection PyUnresolvedReferences
from xml.dom.minidom import Element


来源:https://stackoverflow.com/questions/61208926/i-cant-import-xml-dom-minidom-in-pycharm-what-could-i-try

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!