使当前目录始终为当前想要运行的python程序的目录,而不是最上层目录 使用 os 模块来设置工作目录,使无论代码在什么位置运行,工作目录都会被设置为当前脚本所在的目录 current_dir = os.path.dirname(os.path.abspath(__file__)) os.chdir(current_dir)