MacOS – How to get rid of Python Launcher icon every time a script runs

dockmacospython

Using Sublime Text 2 or Atom (maybe other editors too), when running a simple plotting script in Python, the Python Launcher icon (the rocket) pops up every time I run the code. The icons add up in the Dock , and I have to close them individually. Is there any configuration to avoid this behavior?

With Sublime Text, for instance, Command + B is the default shortcut I use to run a script. I have not found this issue addressed in Atom's or Sublime Text's documentation (neither in Stack Exchange).

The script that I use is a basic fit to some data:

import csv
import matplotlib.pyplot as plt
from scipy.interpolate import *

with open('data.csv', 'rU') as mycsv:
    data = csv.reader(mycsv)
    x = []
    y = []
    for row in data:
        x.append(float(row[0]))
        y.append(float(row[1]))

p = polyfit(x, y, 2)
xp = linspace(-5, 1, 1000)

plt.scatter(x, y)
plt.plot(xp,polyval(p,xp),'r-', label='p1')
plt.show()

Best Answer

I'm not familiar with pyplot, but from the documentation, it looks like the show() method 'holds onto' ("blocks") the script until it is closed by some user interaction.

In non-interactive mode, display all figures and block until the figures have been closed;
A single experimental keyword argument, block, may be set to True or False to override the blocking behavior described above.

Other methods like ginput() and waitforbuttonpress() describe the blocking process.

You could test this by commenting out the last line and see if the icons persist.