NameError: name ‘file’ is not defined 当python在终端或者说在交互式情况下运行时,是无法识别__file__的。 此时要获取当前脚本运行的目录可以使用 os.path.abspath('')