Question

For some years alread I have had the following import in my code:

from etree.ElementTree import fromstring, parse, VERSION

Today I made a mistake while moving (in Eclipse/pyDev) a few unrelated sourcefiles to another folder. The folder was not a package and it cost me some cleans, rebuilds and del *.pyc-s to get them found again. That part has been solved, but now, the import above breaks with "unresoved import...". When I remove the etree-prefix, the imports are resolved, but at runtime I get

from ElementTree import fromstring, parse, VERSION
File "C:\Program Files\Python\EPD-7.3-2x64\Lib\xml\etree\ElementTree.py", line 127, in <module>
from . import ElementPath
ValueError: Attempted relative import in non-package

What is going wrong..?

Was it helpful?

Solution

You should not have been able to.

The import normally would be from xml.etree.ElementTree import ...; the top-level package name is xml.etree, not etree.

It looks as if you added the xml.etree package to the Python sys.path module search path. Don't do that. Remove C:\Program Files\Python\EPD-7.3-2x64\Lib\xml\etree from your sys.path (or the PYTHONPATH environment variable) and import from the correct top-level package name instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top