<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.3%2FDevelopers%2FPython_scripting</id>
	<title>Documentation/4.3/Developers/Python scripting - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.3%2FDevelopers%2FPython_scripting"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.3/Developers/Python_scripting&amp;action=history"/>
	<updated>2026-05-11T15:07:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.3/Developers/Python_scripting&amp;diff=35301&amp;oldid=prev</id>
		<title>UpdateBot: Nightly -&gt; 4.3</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.3/Developers/Python_scripting&amp;diff=35301&amp;oldid=prev"/>
		<updated>2013-09-05T03:37:38Z</updated>

		<summary type="html">&lt;p&gt;Nightly -&amp;gt; 4.3&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;noinclude&amp;gt;{{documentation/versioncheck}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
= Background =&lt;br /&gt;
&lt;br /&gt;
This is an evolution of the [[Slicer3:Python|python implementation in slicer3]].  Slicer's APIs are now natively wrapped in python.  &lt;br /&gt;
&lt;br /&gt;
Topics like plotting are still experimental in slicer4.&lt;br /&gt;
&lt;br /&gt;
See [http://www.na-mic.org/Wiki/index.php/AHM2012-Slicer-Python this 2012 presentation on the state of python in slicer4].&lt;br /&gt;
&lt;br /&gt;
'''See [[4.0/Training#Slicer4_Programming_Tutorial|the python slicer4 tutorial for more examples]].'''&lt;br /&gt;
&lt;br /&gt;
[[Documentation/{{documentation/version}}/Developers/Tutorials/SelfTestModule|Slicer Self Tests]] can be written in python, and provide a good source of examples for manipulating the data, logic, and gui of slicer.&lt;br /&gt;
&lt;br /&gt;
= Start Here for Scripted Module and Extension Development=&lt;br /&gt;
An extensive tutorial and reference page was created [http://www.na-mic.org/Wiki/index.php/2013_Project_Week_Breakout_Session:Slicer4Python for the Slicer/Python breakout session at the NA-MIC 2014 Summer Project Week].&lt;br /&gt;
&lt;br /&gt;
= Usage options =&lt;br /&gt;
&lt;br /&gt;
==Python Interactor==&lt;br /&gt;
&lt;br /&gt;
Use the Window-&amp;gt;Python Interactor (Control-3 on window/linux, Command-3 on mac) to bring up the Qt-based console with access to the vtk, Qt, and Slicer wrapped APIs.&lt;br /&gt;
&lt;br /&gt;
Most python code can be installed and run from this window, but because it exists in the event driven Qt GUI environment, some operations like, like parallel processing or headless operation, are not easily supported.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
&lt;br /&gt;
Start slicer4 and bring up python console.  Load a volume like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; slicer.util.loadVolume(slicer.app.slicerHome + &amp;quot;/share/MRML/Testing/TestData/fixed.nrrd&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Get the volume node for that volume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; n = getNode('fixed')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can use Tab to see lists of methods for a class instance.&lt;br /&gt;
&lt;br /&gt;
==== Accessing Volume data as numpy array ====&lt;br /&gt;
&lt;br /&gt;
You can easily inspect and manipulate volume data using numpy and related code.  In slicer you can do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = array('fixed')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and a will be a pointer to the appropriate data (no data copying).  Scalar volumes become three-dimensional arrays, while vector volumes become 4D, and tensor volumes are 5D.  All arrays can be manipulated directly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Running a CLI from Python ====&lt;br /&gt;
&lt;br /&gt;
Here's an example to create a model from a volume using the [[Documentation/4.0/Modules/GrayscaleModelMaker|Grayscale Model Maker]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def grayModel(volumeNode):&lt;br /&gt;
  parameters = {}&lt;br /&gt;
  parameters[&amp;quot;InputVolume&amp;quot;] = volumeNode.GetID()&lt;br /&gt;
  outModel = slicer.vtkMRMLModelNode()&lt;br /&gt;
  slicer.mrmlScene.AddNode( outModel )&lt;br /&gt;
  parameters[&amp;quot;OutputGeometry&amp;quot;] = outModel.GetID()&lt;br /&gt;
  grayMaker = slicer.modules.grayscalemodelmaker&lt;br /&gt;
  return (slicer.cli.run(grayMaker, None, parameters))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To try this, download the MRHead dataset from the [[Documentation/4.0/Modules/SampleData|Sample Data]] and paste the code into the python console and then run this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
v = getNode('MRHead')&lt;br /&gt;
cliNode = grayModel(v)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the CLI module runs in a background thread, so the call to grayModel will return right away.  But the slicer.cli.run call returns a cliNode (an instance of [http://slicer.org/doc/html/classvtkMRMLCommandLineModuleNode.html vtkMRMLCommandLineModuleNode]) which can be used to monitor the progress of the module.&lt;br /&gt;
&lt;br /&gt;
'' Passing Fiducials to CLIs via a Python Script ''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import SampleData&lt;br /&gt;
sampleDataLogic = SampleData.SampleDataLogic()&lt;br /&gt;
head = sampleDataLogic.downloadMRHead()&lt;br /&gt;
volumesLogic = slicer.modules.volumes.logic()&lt;br /&gt;
headLabel = volumesLogic.CreateLabelVolume(slicer.mrmlScene, head, 'head-label')&lt;br /&gt;
&lt;br /&gt;
fiducialNode = slicer.vtkMRMLAnnotationFiducialNode()&lt;br /&gt;
fiducialNode.SetFiducialWorldCoordinates((1,0,5))&lt;br /&gt;
fiducialNode.SetName('Seed Point')&lt;br /&gt;
fiducialNode.Initialize(slicer.mrmlScene)&lt;br /&gt;
fiducialsList = getNode('Fiducials List')&lt;br /&gt;
&lt;br /&gt;
params = {'inputVolume': head.GetID(), 'outputVolume': headLabel.GetID(), 'seed' : fiducialsList.GetID(), 'iterations' : 2} &lt;br /&gt;
&lt;br /&gt;
cliNode = slicer.cli.run(slicer.modules.simpleregiongrowingsegmentation, None, params , wait_for_completion=True)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'' Checking Status''&lt;br /&gt;
&lt;br /&gt;
In this example we create a simple callback that will be called whenever the cliNode is modified.  The status will tell you if the nodes is Pending, Running, or Completed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def printStatus(caller, event):&lt;br /&gt;
  print(&amp;quot;Got a %s from a %s&amp;quot; % (event, caller.GetClassName()))&lt;br /&gt;
  if caller.IsA('vtkMRMLCommandLineModuleNode'):&lt;br /&gt;
    print(&amp;quot;Status is %s&amp;quot; % caller.GetStatusString())&lt;br /&gt;
&lt;br /&gt;
cliNode.AddObserver('ModifiedEvent', printStatus)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Accessing slice vtkRenderWindows from slice views ====&lt;br /&gt;
&lt;br /&gt;
The example below shows how to get the rendered slice window.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lm = slicer.app.layoutManager()&lt;br /&gt;
redWidget = lm.sliceWidget('Red')&lt;br /&gt;
redView = redWidget.sliceView()&lt;br /&gt;
wti = vtk.vtkWindowToImageFilter()&lt;br /&gt;
wti.SetInput(redView.renderWindow())&lt;br /&gt;
wti.Update()&lt;br /&gt;
v = vtk.vtkImageViewer()&lt;br /&gt;
v.SetColorWindow(255)&lt;br /&gt;
v.SetColorLevel(128)&lt;br /&gt;
v.SetInputConnection(wti.GetOutputPort())&lt;br /&gt;
v.Render()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''TODO: some more samples of the Qt console''&lt;br /&gt;
&lt;br /&gt;
== In iPython ==&lt;br /&gt;
&lt;br /&gt;
'''Important: The example below was developed for an early beta version of slicer4 and is not supported in Slicer 4.0 or 4.1'''&lt;br /&gt;
&lt;br /&gt;
See [http://slicer-devel.65872.n3.nabble.com/import-slicer-problem-in-using-python-in-the-shell-launched-using-quot-slicer-xterm-amp-quot-td3968880.html this thread for information on adapting this approach to Slicer 4.1].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://ipython.scipy.org iPython] is a powerful shell and can also be used to access the vtk and slicer APIs (but not Qt at the moment).&lt;br /&gt;
&lt;br /&gt;
As of Slicer4 beta in February 2011, it is possible to use these steps for installation.  This has only been tested on a ubuntu linux system so far.&lt;br /&gt;
&lt;br /&gt;
These instructions assume you have a Slicer4-superbuild directory created according to the [[Slicer4:Build_Instructions|Slicer4 Build Instructions]].&lt;br /&gt;
&lt;br /&gt;
See the [http://matplotlib.sourceforge.net|matplotlib] website for more example plot types.&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
&lt;br /&gt;
* Get readline - it will make iPython more useful.&lt;br /&gt;
&lt;br /&gt;
 # do this before building slicer4 - or do &amp;quot;cd Slicer4-superbuild/; rm -rf python* ; make&amp;quot;&lt;br /&gt;
 sudo apt-get install libreadline6-dev&lt;br /&gt;
&lt;br /&gt;
cd to your Slicer4-superbuild directory for the rest of these steps&lt;br /&gt;
&lt;br /&gt;
* Install the vtk package in the python tree&lt;br /&gt;
 # TODO: this should be done in superbuild script&lt;br /&gt;
 (cd ./VTK-build/Wrapping/Python;  ../../../Slicer-build/Slicer4 --launch ../../../python-build/bin/python setup.py install)&lt;br /&gt;
&lt;br /&gt;
* Install ipython:&lt;br /&gt;
&lt;br /&gt;
 git clone git://github.com/ipython/ipython.git&lt;br /&gt;
 (cd ./ipython; git checkout 0.10.2)&lt;br /&gt;
 (cd ./ipython;  ../Slicer-build/Slicer4 --launch ../python-build/bin/python setup.py install)&lt;br /&gt;
&lt;br /&gt;
* Install matplotlib (remove the source after installing so python import will not get confused by it.)&lt;br /&gt;
&lt;br /&gt;
 git clone git://github.com/pieper/matplotlib.git&lt;br /&gt;
 (cd ./matplotlib;  ../Slicer-build/Slicer4 --launch ../python-build/bin/python setup.py install)&lt;br /&gt;
 rm -rf matplotlib&lt;br /&gt;
&lt;br /&gt;
=== Now try it! ===&lt;br /&gt;
[[image:Slicer4-matplotlib-2011-02-26.png|thumb|300px|right|python plotting from ipython using slicer libraries]]&lt;br /&gt;
&lt;br /&gt;
Launch an xterm with all the paths set correctly to find the slicer python packages&lt;br /&gt;
&lt;br /&gt;
 ./Slicer-build/Slicer4 --launch xterm &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Now, ''inside the xterm'' launch ipython&lt;br /&gt;
&lt;br /&gt;
 ./python-build/bin/ipython&lt;br /&gt;
&lt;br /&gt;
Inside ipython you can past the following script that does:&lt;br /&gt;
* create a mrml scene and add a volume&lt;br /&gt;
* make a numpy aray from the image data&lt;br /&gt;
* do calculations in numpy and vtk for comparision&lt;br /&gt;
* make a histogram plot of the data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import vtk&lt;br /&gt;
import slicer&lt;br /&gt;
mrml = slicer.vtkMRMLScene()&lt;br /&gt;
vl = slicer.vtkSlicerVolumesLogic()&lt;br /&gt;
vl.SetAndObserveMRMLScene(mrml)&lt;br /&gt;
n = vl.AddArchetypeVolume('../Slicer4/Testing/Data/Input/MRHeadResampled.nhdr', 'CTC')&lt;br /&gt;
i = n.GetImageData()&lt;br /&gt;
print (i.GetScalarRange())&lt;br /&gt;
&lt;br /&gt;
import vtk.util.numpy_support&lt;br /&gt;
a = vtk.util.numpy_support.vtk_to_numpy(i.GetPointData().GetScalars())&lt;br /&gt;
print(a.min(),a.max())&lt;br /&gt;
&lt;br /&gt;
import matplotlib&lt;br /&gt;
import matplotlib.pyplot&lt;br /&gt;
n, bins, patches = matplotlib.pyplot.hist(a, 50, facecolor='g', alpha=0.75)&lt;br /&gt;
matplotlib.pyplot.show()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If all goes well, you should see an image like the one shown here.&lt;br /&gt;
&lt;br /&gt;
=== Parallel Processing === &lt;br /&gt;
&lt;br /&gt;
In the shell, run this to install [http://packages.python.org/joblib/ joblib]&lt;br /&gt;
&lt;br /&gt;
 wget http://pypi.python.org/packages/source/j/joblib/joblib-0.4.6.dev.tar.gz&lt;br /&gt;
 tar xvfz joblib-0.4.6.dev.tar.gz&lt;br /&gt;
 (cd ./joblib-0.4.6.dev;  ../Slicer-build/Slicer4 --launch ../python-build/bin/python setup.py install)&lt;br /&gt;
&lt;br /&gt;
Then in ipython you can run this example: &lt;br /&gt;
&lt;br /&gt;
 from joblib import *&lt;br /&gt;
 from math import *&lt;br /&gt;
 for jobs in xrange(1,8):&lt;br /&gt;
   print (jobs, Parallel(n_jobs=jobs)(delayed(sqrt)(i**2) for i in range(10000))[-1])&lt;br /&gt;
&lt;br /&gt;
=== Packaging/Saving Scenes ===&lt;br /&gt;
&lt;br /&gt;
A basic example.  The following packages all of the scene's referenced files into one specified folder.  All images, csvs, volumes, etc. (everything except the scene .mrml) are copied into the folder &amp;quot;&amp;lt;package dir&amp;gt;/data.&amp;quot;  The scene .mrml is in the &amp;quot;&amp;lt;package dir&amp;gt;&amp;quot; directory. &lt;br /&gt;
&lt;br /&gt;
 import os &lt;br /&gt;
 # Library for OS specific routines&lt;br /&gt;
 &lt;br /&gt;
 tempDir = os.path.join(slicer.app.slicerHome, ‘testScene’) &lt;br /&gt;
 # Put our temp scene directory into the slicer directory.  os.path.join takes care of slash issues that you may encounter with UNIX-Windows compatibility.    &lt;br /&gt;
 &lt;br /&gt;
 os.mkdir(tempDir) &lt;br /&gt;
&lt;br /&gt;
 l = slicer.app.applicationLogic()&lt;br /&gt;
 l.SaveSceneToSlicerDataBundleDirectory(tempDir, None)&lt;br /&gt;
&lt;br /&gt;
=== Loading DICOM Sets ===&lt;br /&gt;
&lt;br /&gt;
The approach is to point Slicer's DICOM database to the directory of the new files.  The command appends the existing database with the files found in the inputted directory.&lt;br /&gt;
 i = ctk.ctkDICOMIndexer()&lt;br /&gt;
 i.addDirectory(slicer.dicomDatabase, '/yourDICOMdir/')&lt;br /&gt;
&lt;br /&gt;
One approach to begin the load process is to call on the DICOM module, which will automatically open the &amp;quot;DICOM Details&amp;quot; popup.  However, if the popup has been used already in the current Slicer session, a refresh may not occur and a restart may be required.&lt;br /&gt;
 m = slicer.util.mainWindow()&lt;br /&gt;
 m.moduleSelector().selectModule('DICOM')&lt;br /&gt;
&lt;br /&gt;
= Resources =&lt;br /&gt;
== Installing Pip ==&lt;br /&gt;
&lt;br /&gt;
In a nutshell, both distribute and pip will have to be installed.&lt;br /&gt;
&lt;br /&gt;
1. Download distribute: http://python-distribute.org/distribute_setup.py&lt;br /&gt;
  &lt;br /&gt;
2. Install distribute: &lt;br /&gt;
&lt;br /&gt;
 $ Slicer distribute_setup.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Number of registered modules: 1 &lt;br /&gt;
Number of instantiated modules: 1 &lt;br /&gt;
Number of loaded modules: 1 &lt;br /&gt;
Loading Slicer RC file [/home/jchris/.slicerrc.py]&lt;br /&gt;
Slicer RC file loaded [09/01/2013 20:23:41]&lt;br /&gt;
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.34.tar.gz&lt;br /&gt;
Extracting in /tmp/tmpW05FBr&lt;br /&gt;
Now working in /tmp/tmpW05FBr/distribute-0.6.34&lt;br /&gt;
Installing Distribute&lt;br /&gt;
File  &amp;quot;/tmp/tmpW05FBr/distribute-0.6.34/qSlicerBaseQTCore_fr.qm&amp;quot;  doesn't exist. &lt;br /&gt;
Number of registered modules: 1 &lt;br /&gt;
Number of instantiated modules: 1 &lt;br /&gt;
Number of loaded modules: 1 &lt;br /&gt;
Loading Slicer RC file [/home/jchris/.slicerrc.py]&lt;br /&gt;
Slicer RC file loaded [09/01/2013 20:24:29]&lt;br /&gt;
Before install bootstrap.&lt;br /&gt;
Scanning installed packages&lt;br /&gt;
No setuptools distribution found&lt;br /&gt;
running install&lt;br /&gt;
running bdist_egg&lt;br /&gt;
running egg_info&lt;br /&gt;
writing distribute.egg-info/PKG-INFO&lt;br /&gt;
writing top-level names to distribute.egg-info/top_level.txt&lt;br /&gt;
[...]&lt;br /&gt;
Installed /home/jchris/Projects/Slicer-AHM-Superbuild-Debug/python-build/lib/python2.6/site-packages/distribute-0.6.34-py2.6.egg&lt;br /&gt;
Processing dependencies for distribute==0.6.34&lt;br /&gt;
Finished processing dependencies for distribute==0.6.34&lt;br /&gt;
After install bootstrap.&lt;br /&gt;
Creating /home/jchris/Projects/Slicer-AHM-Superbuild-Debug/python-build/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info&lt;br /&gt;
Creating /home/jchris/Projects/Slicer-AHM-Superbuild-Debug/python-build/lib/python2.6/site-packages/setuptools.pth&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Download pip: https://raw.github.com/pypa/pip/master/contrib/get-pip.py&lt;br /&gt;
&lt;br /&gt;
4. Install pip: &lt;br /&gt;
&lt;br /&gt;
  $ Slicer get-pip.py&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Number of registered modules: 1 &lt;br /&gt;
Number of instantiated modules: 1 &lt;br /&gt;
Number of loaded modules: 1 &lt;br /&gt;
Loading Slicer RC file [/home/jchris/.slicerrc.py]&lt;br /&gt;
Slicer RC file loaded [09/01/2013 20:41:29]&lt;br /&gt;
Downloading/unpacking pip&lt;br /&gt;
  Running setup.py egg_info for package pip&lt;br /&gt;
    Number of registered modules: 1&lt;br /&gt;
    Number of instantiated modules: 1&lt;br /&gt;
    Number of loaded modules: 1&lt;br /&gt;
    Loading Slicer RC file [/home/jchris/.slicerrc.py]&lt;br /&gt;
    Slicer RC file loaded [09/01/2013 20:41:38]&lt;br /&gt;
    warning: manifest_maker: standard file '' not found&lt;br /&gt;
    warning: no files found matching '*.html' under directory 'docs'&lt;br /&gt;
    warning: no previously-included files matching '*.txt' found under directory 'docs/_build'&lt;br /&gt;
    no previously-included directories found matching 'docs/_build/_sources'&lt;br /&gt;
Installing collected packages: pip&lt;br /&gt;
  Running setup.py install for pip&lt;br /&gt;
    Number of registered modules: 1&lt;br /&gt;
    Number of instantiated modules: 1&lt;br /&gt;
    Number of loaded modules: 1&lt;br /&gt;
    Loading Slicer RC file [/home/jchris/.slicerrc.py]&lt;br /&gt;
    Slicer RC file loaded [09/01/2013 20:41:41]&lt;br /&gt;
    warning: manifest_maker: standard file '' not found&lt;br /&gt;
    warning: no files found matching '*.html' under directory 'docs'&lt;br /&gt;
    warning: no previously-included files matching '*.txt' found under directory 'docs/_build'&lt;br /&gt;
    no previously-included directories found matching 'docs/_build/_sources'&lt;br /&gt;
    Installing pip script to /home/jchris/Projects/Slicer-AHM-Superbuild-Debug/python-build/bin&lt;br /&gt;
    Installing pip-2.6 script to /home/jchris/Projects/Slicer-AHM-Superbuild-Debug/python-build/bin&lt;br /&gt;
Successfully installed pip&lt;br /&gt;
Cleaning up...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For additional information regarding installation of pip. See http://www.pip-installer.org/en/latest/installing.html&lt;br /&gt;
&lt;br /&gt;
== Using Pip ==&lt;br /&gt;
&lt;br /&gt;
1. Within the Slicer python interactor:&lt;br /&gt;
&lt;br /&gt;
  ./Slicer --no-main-window --disable-cli-modules --disable-loadable-modules --disable-scripted-loadable-modules --show-python-interactor&lt;br /&gt;
&lt;br /&gt;
2. Define the function &amp;lt;code&amp;gt;install_distributions&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def install_distributions(distributions):&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  Copied from http://threebean.org/blog/2011/06/06/installing-from-pip-inside-python-or-a-simple-pip-api/&lt;br /&gt;
  &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
  import pip.commands.install&lt;br /&gt;
  command = pip.commands.install.InstallCommand()&lt;br /&gt;
  opts, args = command.parser.parse_args()&lt;br /&gt;
  # TBD, why do we have to run the next part here twice before actual install&lt;br /&gt;
  requirement_set = command.run(opts, distributions)&lt;br /&gt;
  requirement_set = command.run(opts, distributions)&lt;br /&gt;
  requirement_set.install(opts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Try to install a package&lt;br /&gt;
&lt;br /&gt;
 install_distributions([&amp;quot;Markdown&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
=Issues=&lt;br /&gt;
* matplotlib currently uses Tk to show the window on Linux and it does not handle pan/zoom events correctly.  Ideally there would be a PythonQt wrapper for the plots and this is probably required for use on windows (and maybe mac).&lt;br /&gt;
&lt;br /&gt;
* the matplotlib window is in the same thread with the ipython window so you cannot keep the plot open while working on the next one.  However you can save the plot to a file (png, pdf, etc...) and look at it with another program while working in ipython.&lt;br /&gt;
&lt;br /&gt;
* in slicer4 the PythonQt package is loaded as 'qt', however matplotlib tries running 'import qt' as a way to determine if it is running in PyQt version 3.  Because of this a patched version of matplotlib is required (see [https://github.com/pieper/matplotlib/commit/23bca600c27924450128bfe6e68196eb87cf0654 this diff])&lt;br /&gt;
&lt;br /&gt;
* Tested in Windows 7: Python 2.6.6 (used in Slicer 4.1) has errors in referencing its XML DOM parsers, such as ElementTree.  This is a Windows-specific issue -- the same code works in Linux Ubuntu.  Solution thus far is to write your own XML parser.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{:Documentation/{{documentation/version}}/Developers/FAQ/Python Scripting|Python Scripting}}&lt;/div&gt;</summary>
		<author><name>UpdateBot</name></author>
		
	</entry>
</feed>