Python XML No module named Etree. ElementTree

Source: Internet
Author: User

In the process of learning to parse XML using Python, use the examples in the official document https://docs.python.org/2/library/xml.etree.elementtree.html to test the code as follows:

Import Xml.etree.ElementTree as Ettree = Et.parse ('/home/huayuan/code/xml.py ') root = Tree.getroot ()


Try to run, did not think unexpectedly will error:

Traceback (most recent):

File "/home/huayuan/code/xml.py", line 1, <module>

Import Xml.etree.ElementTree as ET

File "/home/huayuan/code/xml.py", line 1, <module>

Import Xml.etree.ElementTree as ET

Importerror: No module named Etree. ElementTree

[Finished in 0.1s with exit code 1]


Check Python's library path/usr/lib/python2.7/xml/etree and find that the xml.etree.Element package is normal, such as:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/4A/0C/wKioL1QhiuThkrS3AAClZJ0PNA4158.jpg "title=" Python.png "alt=" Wkiol1qhiuthkrs3aaclzj0pna4158.jpg "/>


Reading the wrong hint is import xml.etree.ElementTree as ET this sentence has a problem, so try to make different changes to it, the results will not help.


Finally can only resort to Baidu, search for a long time, found that netizens seem to have busty smooth, almost no one mentioned that there is such a situation.


Later, at last in a humble corner to see this sentence: do not use XML as the file name.


I just named the code file as a xml.py, immediately renamed, and then run. The result is still not, careful investigation, found that the generated XML.PYC file also exists, it may be caused by the impact, deleted the retry, and finally run smoothly.


Summarize:

Looking back, this can be said to be a low-level error, Python refers to the package should be first in the code file in the folder to find, the file name of xml.py, import xml.etree.Element This sentence in the current folder to find their own source files, their written xml.py inside there is no etree.element these modules, of course, is to error.







This article is from the "Free Self" blog, please be sure to keep this source http://hhuayuan.blog.51cto.com/1630327/1557536

Python XML No module named Etree. ElementTree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.