这是什么Python图标? [英] What is this Python Icon?

查看:428
本文介绍了这是什么Python图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时当我在终端中运行python脚本时,会打开一个python实例

Sometimes when I run python scripts in terminal a python instance opens up

我已经看到matplotlib和ghost导致了这种情况.关闭它的唯一方法似乎是关闭python终端.

I've seen matplotlib and ghost cause this. The only way to close it seems to be to close the python terminal.

该实例究竟是什么?如何在脚本执行后自动关闭它?

What exactly is this instance and how do I have it close automatically after my script executes?

推荐答案

在OS X上,只要您执行与GUI交互的操作,Dock就会显示Python图标.最常见的原因是将matplotlib与GUI后端一起使用(例如PyQt).使用交互式后端(例如PyQt)时,通常在调用plt.show()后会看到一个火箭图标,该图标将保留在Dock中,直到关闭窗口并与GUI交互的进程退出.

On OS X the Dock will display an icon for Python whenever you do something that interacts with the GUI. The most common reason for this is using matplotlib with a GUI backend (e.g. PyQt). When using an interactive backend (e.g. PyQt) you will normally see a rocket icon after you call plt.show() which will remain on the Dock until after the window is closed and process that interacted with the GUI exits.

在Python shell中进行交互工作时,图标停留在此不是因为 Terminal 仍处于打开状态(或脚本仍在执行),而是因为Python进程仍处于活动状态.此过程可能是在后台维护GUI事件循环.

When you are working interactively in the Python shell, the icon stays there not because the Terminal is still open (or script is still executing) but because the Python process is still active. This process is probably maintaining a GUI event loop in the background.

有一些解决方案:

  • matplotlib中,您可以使用plt.show(block=False)断开事件循环,这意味着图标将在关闭窗口后消失.
  • 设置非交互式后端,例如matplotlib.use("Agg")完全避免创建窗口.当然,您什么也看不到.
  • 修改Python.app .plist以隐藏图标.
  • In matplotlib you can use plt.show(block=False) to detach the event loop, meaning the icon will disappear once the window is closed.
  • Set a non-interactive backend, e.g. matplotlib.use("Agg") to avoid creating the windows at all. Of course, you can't see anything.
  • Modify the Python.app .plist to suppress icons.

对于后者,此处的说明(博士.Drang)如下.请注意,这是针对系统Python的,对于其他位置,您需要在其他位置找到.plist:

For the latter, the instructions here (Dr. Drang) are as follows. Note this is for the system Python, for other locations you'll need to find the .plist elsewhere:

cd /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/

# NB the following file is binary, use a compatible editor or convert with
sudo plutil -convert xml1 Info.plist # Convert to XML
sudo chmod 666 Info.plist # Make editable

然后在最终的</dict>

<key>LSUIElement</key>
<true/>    

返回二进制文件并修复权限:

Return to binary and fix permissions:

sudo chmod 644 Info.plist
sudo plutil -convert binary1 Info.plist

这篇关于这是什么Python图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆