In my Django project, the following line throws an ImportError: “No module named elementtree”.
from elementtree import ElementTree
However, the module is installed (ie, I can run an interactive python shell, and type that exact line without any ImportError), and the directory containing the module is on the PYTHONPATH. But when I access any page in a browser, it somehow can’t find the module, and throws the ImportError. What could be causing this?
Can you import
elementtreewithin the django shell:Assuming you have multiple python versions and do not know which one is being used to run your site, add the following to your view and push
python_verto your template, it will show you the Python version you are using:You can also explicitly add the path to elementtree programatically in your
settings.py: