<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>Pylab inline in windows virtualenv</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">I am trying to invoke ipython as:</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Ipython qtconsole --pylab=inline</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">From within a virtual_env on Windows 7. Previously, I was having trouble with IPython 'recognizing' the virtual_env -- it was starting from the virtualenv's interpreter but not including the virtual_env's PYTHONPATH directories in sys.path. I worked around this issue by including a startup script in my IPython profile to append the appropriate directories to IPython's sys.path, using a modified version of the script shown here:</FONT></P>
<P><A HREF="http://igotgenes.blogspot.co.uk/2010/01/interactive-sandboxes-using-ipython.html"><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://igotgenes.blogspot.co.uk/2010/01/interactive-sandboxes-using-ipython.html</FONT></U></A>
</P>
<P><FONT SIZE=2 FACE="Arial">This worked well until I tried to use pylab inline. I have installed matplotlib in the virtual_env, rather than the system's default site directory. If I start IPython qtconsole without the --pylab=inline flag, then I can do:</FONT></P>
<P> <FONT SIZE=2 FACE="Arial">In [1]: import matplotlib</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">In [2]: matplotlib</FONT>
<BR> <FONT SIZE=2 FACE="Arial">Out[2]: <module 'matplotlib' from ...></FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">However, when I try to use the --pylab=inline flag, it would seem the path changing script isn't called until after the qtconsole has already tried to import matplotlib:</FONT></P>
<P> <FONT SIZE=2 FACE="Arial">Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]</FONT>
<BR> <FONT SIZE=2 FACE="Arial">Type "copyright", "credits" or "license" for more information.</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">IPython 0.12.1 -- An enhanced Interactive Python.</FONT>
<BR> <FONT SIZE=2 FACE="Arial">? -> Introduction and overview of IPython's features.</FONT>
<BR> <FONT SIZE=2 FACE="Arial">%quickref -> Quick reference.</FONT>
<BR> <FONT SIZE=2 FACE="Arial">help -> Python's own help system.</FONT>
<BR> <FONT SIZE=2 FACE="Arial">object? -> Details about 'object', use 'object??' for extra details.</FONT>
<BR> <FONT SIZE=2 FACE="Arial">%guiref -> A brief reference about the graphical user interface.</FONT>
<BR> <FONT SIZE=2 FACE="Arial">---------------------------------------------------------------------------</FONT>
<BR> <FONT SIZE=2 FACE="Arial">ImportError Traceback (most recent call last)</FONT>
<BR> <FONT SIZE=2 FACE="Arial">...\ipython-0.12.1-py2.7.egg\IPython\zmq\ipkernel.pyc in init_kernel(self)</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> 592 if self.pylab:</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> 593 try:</FONT>
<BR> <FONT SIZE=2 FACE="Arial">--> 594 gui, backend = pylabtools.find_gui_and_backend(self.pylab)</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> 595 shell.enable_pylab(gui, import_all=self.pylab_import_all)</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> 596 except Exception:</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">...\ipython-0.12.1-py2.7.egg\IPython\core\pylabtools.pyc in find_gui_and_backend(gui)</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> 194 """</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> 195 </FONT>
<BR> <FONT SIZE=2 FACE="Arial">--> 196 import matplotlib</FONT>
<BR> <FONT SIZE=2 FACE="Arial"> 197 </FONT>
<BR> <FONT SIZE=2 FACE="Arial"> 198 if gui and gui != 'auto':</FONT>
</P>
<P> <FONT SIZE=2 FACE="Arial">ImportError: No module named matplotlib</FONT>
<BR> <FONT SIZE=2 FACE="Arial">Error initializing pylab, pylab mode will not be active</FONT>
<BR> <FONT SIZE=2 FACE="Arial">VIRTUAL_ENV -> d:\Dev\python\venv\veiv_img_proc\Lib\site-packages</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Can anyone suggest a better way to get IPython to work properly with virtual_env on Windows, or a better way to invoke pylab with the qtconsole back-end?</FONT></P>
<P><FONT SIZE=2 FACE="Arial">Thanks and regards,</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Adam</FONT>
</P>
<P>
</P>
</BODY>
</HTML>