32

每当我在 OS X 10.8 上运行打开任何类型窗口的 Python 脚本时,无论是 GLUT 窗口还是 QT 窗口或其他任何窗口,我都会收到如下所示的消息:

2013-09-11 14:36:53.321 Python[3027:f07] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/0x/25_70mj17tb1ypm1c_js8jd40000gq/T/org.python.python.savedState

我使用通过 MacPorts 安装的 python2.7。

这是一个小烦恼,但我很想知道该消息的含义,以及我是否可以采取任何措施来防止它。是因为我的系统配置错误,还是每个人都明白这一点?

4

3 回答 3

51

正确的运行命令是:

defaults write org.python.python ApplePersistenceIgnoreState NO

由于较新版本的 OS X 中的“应用程序恢复”功能而出现此消息。显然,对于大多数 Python 程序(在我的情况下,使用 matplotlib 绘制数据)来说,这不是一个有用的功能,因此我们可以将其关闭上面的命令。

有关defaults write实际操作的更多信息,请查看手册页

于 2014-03-17T22:47:01.863 回答
29

回答我自己的问题,感谢@Steve Barnes 给我提示。看来这个问题可以用终端命令解决

$ defaults write org.python.python ApplePersistenceIgnoreState NO

在评论中,Greg Coladonato 报告说,在 2020 年,运行 Python 3,这可能需要更改为

$ defaults write org.python.python3 ApplePersistenceIgnoreState NO

我不确定这个命令到底是如何操作的,但是前段时间完成了它,我没有观察到任何不良影响。

但是请注意,另一位用户指出,这可能会导致山狮上的 python 3.4 出现错误,当按下按钮时,tkinter 对话框不会按预期关闭。

$ defaults write org.python.python ApplePersistenceIgnoreState YES

如果您遇到问题,将撤消该命令。org.python.python(根据org.python.python3需要更换。)

于 2014-02-05T02:37:12.580 回答
5

运行 anaconda python 发行版时,需要稍微不同的写入:

defaults write com.continuum.python ApplePersistenceIgnoreState NO

于 2016-06-12T21:42:14.437 回答