Please run with 'pythonw', not 'python' -- cannot make plots in python/ipython from cmd line OSX

1.9k Views Asked by At

I am completely new to python installation and took the route of using the Enthought Canopy distribution of python 2.7.6 for my OSX 10.6 32-bit

I have the notebook working smoothly along with everything inside of the Canopy interface. However, when I run the same script:

#!/usr/bin/python
import pylab
import numpy as np
import matplotlib.pyplot as plt

plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

in the command line using 'python ~/Docs/test.py' or 'ipython ~/Docs/test.py' I get this error:

This program needs access to the screen.
Please run with 'pythonw', not 'python', and only when you are logged
in on the main display of your Mac.

which I have searched and find some information here but since it is functioning in Canopy, pythonw, and notebook, I'm not sure this is the answer to my problem. I just don't see why there would be a different backdoor for python and ipython in the command line. Did I say that right?

Also, would installation using homebrew remedy this problem? I like to be able to use the canopy gui, but it seems like once canopy is installed it changes everything. I ask this because I am getting a new mac shortly and have found considerably more streamlined installation procedures here and a virtual environment set-up guide here. But I still want to have the Canopy GUI as an option.

Thankyou in advance.

Edit:

Alright, ipython notebook gives the same error. I closed and restarted it. It was because I invoked %pylab inline. I was not clearing the memory after each run.

1

There are 1 best solutions below

0
On BEST ANSWER

You can write:

ipython --pylab=osx

and

ipython notebook --pylab=osx

as a workaround to get the graphics for these two. Documentation here: https://support.enthought.com/entries/22861925-OS-X-10-9-Mavericks-Python-Canopy

Anyone know how to set this to default?

Though using %pylab inline is what you want if you want to keep all of your graphics within the ipython notebook. Choosing osx will open windows outside of the browser. So you can write ipython notebook --pylab=inline to invoke this.