开发者

'No module named' error in Python while importing outside /home directory

Probably this is a silly issue, but I haven't been able to figure it out.

I'm getting ImportError: No module named etree.ElementTree when I write:

#!/usr/bin/python3.2
import xml.etree.ElementTree as etree
tree = etree.parse('feed.xml')
root = tree.getroot()

If I run this same script in /home/ or /home/<user>/, it works fine but when my current working directory is /home/<user>/<some_directory>/<some_subdirectory>, I get the above mentioned error.

What is happening here?

Additional info: I'm running Ubuntu 11.04 and Pyt开发者_运维知识库hon 3.2

Thanks in advance.


Try running Python in the place where it works and the place where it doesn't work, and compare the values of sys.path when running Python in those two locations.

My first guess would be that you have $PYTHONSTARTUP set to something that depends on the working directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜