“没有名为的模块”在 /home 目录外部导入时 Python 出错
可能这是一个愚蠢的问题,但我一直无法弄清楚。
当我编写以下内容时,我收到 ImportError: No module named etree.ElementTree
:
#!/usr/bin/python3.2
import xml.etree.ElementTree as etree
tree = etree.parse('feed.xml')
root = tree.getroot()
如果我在 /home/
或 /home/
,它工作正常,但是当我当前的工作目录是 /home/
时,我得到上述内容 错误。
这里发生了什么?
附加信息:我正在运行 Ubuntu 11.04 和 Python 3.2
提前致谢。
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 Python 3.2
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在Python可以工作的地方和不可以工作的地方运行Python,并比较在这两个位置运行Python时的
sys.path
的值。我的第一个猜测是您将
$PYTHONSTARTUP
设置为取决于工作目录的内容。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.