Slicer-Python Packages Use and Install

Since Slicer bundles its own python, it is generally NOT possible to simply copy python packages (especially the one including binaries) from your own site-packages into the one of Slicer.

That said, depending on the platform there is way around it.

First, I suggest you download the latest nightly build of Slicer.

There are a lot of improvement regarding the python infrastructure. It for example includes an updated setuptools as well as pip.

Second, on linux (and most likely macOS), it is indeed possible to pip install official packages (even the including binaries like scipy, tensorflow, …).

On windows, it will currently work only for pure python wheels because the official package for python 2.7 are built with a compiler than the one used for the official wheels. Note that this will change as soon as we standardize on Visual Studio 2015 and switch to python >= 3.5.

As mentioned above, the good news is that pip is available in Slicer.

build tree

From a build tree, you can do:

./Slicer --launch ../python-install/bin/pip install scipy

or something like this on windows (only for pure python wheels)

Slicer.exe --launch ..\python-install\bin\pip.exe install name-of-pure-python-wheel

install tree or python interactor

Since we do not (yet) package the pip executable, you will have to use a different approach.

from the terminal
./Slicer --launch ./bin/python-real -c "import pip; pip.main(['install', 'scipy'])"

or something like this on windows

Slicer.exe --launch bin\python-real.exe -c "import pip; pip.main(['install', 'scipy'])"
from python interactor
import pip
pip.main(['install', 'scipy'])
1 Like