Using the IPython REPL with PTVS


PTVS has a number of REPL modes to choose from:




Editing / Debugging



Default REPL, talks to Python directly

Edit: Standard Editing (arrows, multiline, etc).

Debug: No


IPython with Pylab

REPL talks to IPython backend

Edit: Standard + IPython commands + Pylab conveniences
Debug: No

Yes, inline in REPL

IPython w/o Pylab

REPL talks to IPython backend

Edit: Standard + IPython

Debug: No

Yes, separate window

Note that there’s also the “Debug REPL”, which is the standard REPL, but is aware of the current debugging context.

In this tutorial we’ll cover IPython/matplotlib/etc.

Installing IPython

We highly recommend installing IPython, matplotlib and their dependencies from a distro and not via PyPi. For this tutorial, we’ll use the package from UCI’s Python Extensions page:

Configuring IPython in PTVS

1. First let’s make sure IPython/matplotlib have been installed on your system & work properly.  Go to your Python installation directory and start IPython in Pylab mode (ipython --pylab), and enter the following:

x = linspace(0, 5, 10)
y = x ** 2
plot(x, y, 'r')

Assuming everything is configured properly, you should see something like this:


2. Now let’s make sure PTVS can find all the right bits (IPython, matplotlib, etc):

- Bring up the Python Interpreters window by typing Ctrl-K-` (backtick). Here we see that Python 2.7 64-bit has been selected (Make Default):


- Click the View in File Explorer link and make sure you can see IPython & matplotlib in your Lib\site-packages directory:


3. On the Interpreters Windows, click the Interactive Options and set Interactive Mode to IPython:


4. On the Interpreters Window, click the Interactive Window link to bring up the REPL window (or Alt-I). Now click the blue curved arrow (top left) to RESET the REPL from the previous mode (eg Standard to IPython mode):


5.  Now we’re in IPython mode with Pylab. Let’s try to plot something. Enter this in the REPL:

x = linspace(0, 5, 10)
y = x ** 2
plot(x, y, 'r')

you should see a graph like this inline:


If you hit enter again, you’ll see that the image becomes a thumbnail:


However you can place the mouse pointer on the image and resize it if necessary:


Entering, pasting and sending code to the REPL

Instead of typing in the REPL, you can select text in the Editor and use CTRL-E-E to send it to IPython. Try pasting this code into the Editor, then to the REPL via CTRL-A, CTRL-E-E:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]): 
    xs = np.arange(20) 
    ys = np.random.rand(20)

    # You can provide either a single color or an array. To demonstrate this,
    # the first bar of each set will be colored cyan.

    cs = [c] * len(xs)
    cs[0] = 'c', ys, zs=z, zdir='y', color=cs, alpha=0.8)




When sending code to the Interactive window  (by using Ctrt-E-E), the commands are sent to IPython as one unit to avoid giving you intermediate “partial” graphs:


So far all the images have been inline in the REPL window.  If you run the code from the Editor (CTRL-F5, or right click on the file name & choose Run w/o Debugging), you’ll get a standalone matplotlib window:


Shell commands, magics, etc.

IPython has a number of useful features such as escaping to the system shell, variable substitution, capturing output, etc. Please refer to the IPython reference guide for further information:


IPython notebook mode

You can also use IPython in “notebook” mode where you can use any browser on any OS as the canvas. The backend IPython engine can be local on your machine, or remote. Windows Azure has support for running IPython on a Windows or Linux VM.


Please see the following for details:





Note that IronPython does not support IPython, despite the fact that you can select it  on the Interactive Options form.  You can upvote the feature request or implement it if you’d like!

Last edited Sep 10, 2013 at 8:29 PM by huguesv, version 20


BoulderPip Dec 30, 2013 at 11:27 AM 
I'm getting network errors from without end. I also failed to "pip" matplotlib et al manually on a python 3.3 x64 setup. Please improve the situation.