我正在尝试运行一个需要另一个目录中的包的脚本。在
这是有效的:
execfile("../test.py")
在包父目录中启动python时sys.path.append("package parent")
在python解释器中调用{这不起作用(给出一个ImportError
):
python ../test.py
在包父目录中时python test.py
在脚本目录中时test.py
文件包含我在解释器中使用的相同的sys.path.append
指令。在文件中运行还是在解释器中运行有区别?在
我的目录结构:
我得到的错误消息是:
from package.stuff import SomeClass
ImportError: No module named package.stuff
交互式shell的行为与脚本行为不同的提示可以在^{的docs中找到:
这应该可以解释为什么从交互式shell执行是有效的。但是,如果没有进一步的信息,只能猜测脚本失败的原因。在
设置
PYTHONPATH
与更新sys.path
基本相同。在这个上{cd4}:查看this post和the docs了解详细信息。在
相关问题 更多 >
编程相关推荐