python图标什么意思_这是什么Python图标?

1586010002-jmsa.png

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

PTjJi.png

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?

解决方案

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.

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.

There are a few solutions:

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.

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

Then add the following before the final

LSUIElement

Return to binary and fix permissions:

sudo chmod 644 Info.plist

sudo plutil -convert binary1 Info.plist

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值