Slicer-Python Packages Use and Install

To run as admin, you need to do right click -> run as admin

Other since you installed Slicer, there is no pip exe.

I’ve tried this on the latest nightly version and it all works well for me!

  1. Start Slicer as administrator: in the start menu, instead of left-click on the Slicer icon, use right-click, then select More... and Run as Administrator.

  2. Install a package by using pip. For example, installing of requests package:

Enter this into the Python interactor:

import pip
pip.main(['install', 'requests'])

The package is successfully downloaded and installed:

Collecting requests
  Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
Collecting idna<2.7,>=2.5 (from requests)
  Downloading idna-2.6-py2.py3-none-any.whl (56kB)
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
Collecting certifi>=2017.4.17 (from requests)
  Downloading certifi-2017.7.27.1-py2.py3-none-any.whl (349kB)
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
Installing collected packages: idna, urllib3, certifi, chardet, requests
  Found existing installation: chardet 2.3.0
    Uninstalling chardet-2.3.0:
      Successfully uninstalled chardet-2.3.0
Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22
0

Dependent packages are updated, therefore before using the installed requests package, you need to restart Slicer (you can use the restart() command in the Python console).

Exactly. For pure python packages, that will work great.

Hi,

Thank you very much for all the help!

While the installation worked well for some packages (e.g. PIL and matplotlib wheels), it still doesn’t work for “scipy”, “sckimage”, etc. Does anyone know what happened? Thank you!

  • I did uninstall numpy and installed numpy+mkl since scipy complained numpy didn’t have mkl.

In particular, I get the following error,

path=r"C:\Program Files\Slicer 4.7.0-2017-09-05\packages\scipy-0.19.1-cp27-cp27m-win_amd64.whl"
>>> pip.main(['install',path])
Processing c:\program files\slicer 4.7.0-2017-09-05\packages\scipy-0.19.1-cp27-cp27m-win_amd64.whl
Requirement already satisfied: numpy>=1.8.2 in c:\program files\slicer 4.7.0-2017-09-05\lib\python\lib\site-packages\numpy-1.13.1-py2.7-win-amd64.egg (from scipy==0.19.1)
Exception:
Traceback (most recent call last):
File "C:\Program Files\Slicer 4.7.0-2017-09-05\lib\Python\Lib\site-packages\pip\basecommand_.py", line 215, in main
status = self.run(options, args)
File "C:\Program Files\Slicer 4.7.0-2017-09-05\lib\Python\Lib\site-packages\pip\commands\install_.py", line 335, in run
wb.build(autobuilding=True)
File "C:\Program Files\Slicer 4.7.0-2017-09-05\lib\Python\Lib\site-packages\pip\wheel_.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "C:\Program Files\Slicer 4.7.0-2017-09-05\lib\Python\Lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Program Files\Slicer 4.7.0-2017-09-05\lib\Python\Lib\site-packages\pip\req\req_set.py", line 666, in _prepare_file
check_dist_requires_python(dist)
File "C:\Program Files\Slicer 4.7.0-2017-09-05\lib\Python\Lib\site-packages\pip\utils\packaging_.py", line 48, in check_dist_requires_python
feed_parser.feed(metadata)
File "C:\Program Files\Slicer 4.7.0-2017-09-05\lib\Python\Lib\email\feedparser_.py", line 177, in feed
self._input.push(data)
File "C:\Program Files\Slicer 4.7.0-2017-09-05\lib\Python\Lib\email\feedparser_.py", line 99, in push
parts = data.splitlines(True)
AttributeError: 'NoneType' object has no attribute 'splitlines'

I am trying to install scikit-image with

./Slicer --launch ./bin/python-real -c “import pip; pip.main([‘install’, ‘scikit-image’])”

In the install tree I get the error

/usr/bin/gcc-4.6 -pthread -Wall -Wstrict-prototypes -fno-strict-aliasing -fwrapv -g -fPIC -I/Data-work/BuildDirs/Slicer-4.7.0-2017-09-24-linux-amd64/lib/Python/include/python2.7 -c _posixsubprocess.c -o build/temp.linux-x86_64-2.7/_posixsubprocess.o
_posixsubprocess.c:3:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command '/usr/bin/gcc-4.6' failed with exit status 1

Slicer’s pip does not yet support packages that need compilation. To get access to all Python packages, you have to build Slicer with your Python distribution. See some information here: https://www.slicer.org/wiki/Documentation/Labs/SlicerCondaIntegration

Hi all,

a quick questions concerning this topic. I am developing with Slicer on Windows and was also trying to install a module with precompiled data, namely pywin32. After some try and error I figured out that pywin32 also uses precompiled data. Since Slicers Python is build with VS2013 but the module has precompiled with VS2008 I assume the runtimes collide here.
My plan was now to build Slicer on my own such that I also have a Python.exe build with VS2013. Afterwards I would go to pywin32 gitlab page and build the module manually as well. Building pywin32 requires the Python.exe file, thats why I need to build Slicer as well.

Could this work?

Thanks!

If you build Slicer according to build instructions and you build the Python package using the same compiler and compiler settings then it should all work. If you need a Python.exe, you can use Slicer’s SlicerPython.exe.

Note that Slicer includes Qt library, which provides access to lots of Windows APIs (and Linux and macOS APIs), so you might be able to do without pywin32.

1 Like

Thanks! I think you are right and I should use the Qt library. Haven’t thought about this. Anyways it’s good to know that it should work like this.

If the API is not available in Qt, or you need code to work outside the Slicer environment too, then you could also try pywincffi. That uses the CFFI module, which can construct calls at runtime via ctypes/libffi (in CPython), and avoid the need for dealing with compiled shim libraries.

1 Like

WHy pip.main not working for me. I run as administrator even then its not working for me
Python 2.7.13 (default, Aug 31 2018, 23:24:30) [MSC v.1900 64 bit (AMD64)] on win32
AttributeError: ‘module’ object has no attribute ‘main’

Details can be found Pip in nightly build not working

1 Like

how did you install matplotlib and other packages you mentioned.
For me scipy is installed like this.
from pip._internal import main as pipmain
pipmain([‘install’,‘scipy’])

Collecting scipy

Downloading https://files.pythonhosted.org/packages/d2/a7/0d698589a3c6c44f81078a52518c8e64c4ed579a862105b2bff5a1f14ff4/scipy-1.1.0-cp27-none-win_amd64.whl (31.5MB)

Requirement already satisfied: numpy>=1.8.2 in d:\slicer 4.9.0-2018-08-31\lib\python\lib\site-packages\numpy-1.13.1-py2.7-win-amd64.egg (from scipy) (1.13.1)

Installing collected packages: scipy

Successfully installed scipy-1.1.0
>>> pipmain([‘install’,‘scipy’])

Collecting scipy

Downloading https://files.pythonhosted.org/packages/d2/a7/0d698589a3c6c44f81078a52518c8e64c4ed579a862105b2bff5a1f14ff4/scipy-1.1.0-cp27-none-win_amd64.whl (31.5MB)

Requirement already satisfied: numpy>=1.8.2 in d:\slicer 4.9.0-2018-08-31\lib\python\lib\site-packages\numpy-1.13.1-py2.7-win-amd64.egg (from scipy) (1.13.1)

Installing collected packages: scipy

Successfully installed scipy-1.1.0

>>> pipmain([‘install’,‘scipy’])

Collecting scipy

Downloading https://files.pythonhosted.org/packages/d2/a7/0d698589a3c6c44f81078a52518c8e64c4ed579a862105b2bff5a1f14ff4/scipy-1.1.0-cp27-none-win_amd64.whl (31.5MB)

Requirement already satisfied: numpy>=1.8.2 in d:\slicer 4.9.0-2018-08-31\lib\python\lib\site-packages\numpy-1.13.1-py2.7-win-amd64.egg (from scipy) (1.13.1)

Installing collected packages: scipy

Successfully installed scipy-1.1.0

1 Like

Why I cant install this package

pipmain([‘install’,‘scikit-fuzzy’])

Collecting scikit-fuzzy

Using cached https://files.pythonhosted.org/packages/fb/79/71a79d2663ed662d30461aca261baff4fc87ddfd23f3e9baeaee86917f6b/scikit-fuzzy-0.3.1.tar.gz

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: ‘c:\users\22374464\appdata\local\temp\pip-req-tracker-v9vnky\6fa5e984c9f7c4180f5cbc9dc5bc4378cf0a090dcb740963746419f9’

1 Like

See more details in this post - see above.

Hi,
I tried to install scikit-image but this is what I get

from pip._internal import main as pipmain

&gt;&gt;&gt; pipmain(['install','scikit-image'])

Collecting scikit-image

Downloading https://files.pythonhosted.org/packages/0b/77/909865af5c9dd0fae58723e599747d204586096fd56199d51c6dcb0262e7/scikit_image-0.14.0-cp27-none-win_amd64.whl (24.7MB)

Collecting dask[array]&gt;=0.9.0 (from scikit-image)

Downloading https://files.pythonhosted.org/packages/ea/e7/f01b2e72b4c235ee23c7730424b7bb0b36f1e93c90c129a8a14d7984ba5f/dask-0.19.1-py2.py3-none-any.whl (655kB)

Requirement already satisfied: six&gt;=1.10.0 in d:\slicer 4.9.0-2018-08-31\lib\python\lib\site-packages (from scikit-image) (1.11.0)

Collecting pillow&gt;=4.3.0 (from scikit-image)

Downloading https://files.pythonhosted.org/packages/48/91/f058672c494e186dc900bb6253e8cbde3307da17aed0a2d1ebcfb80ab766/Pillow-5.2.0-cp27-cp27m-win_amd64.whl (1.5MB)

Collecting PyWavelets&gt;=0.4.0 (from scikit-image)

Downloading https://files.pythonhosted.org/packages/60/b4/d54dcf1c614ddf219fbb3612e6b0981706406ef54c1d2430be2efc5084cc/PyWavelets-1.0.0-cp27-none-win_amd64.whl (4.2MB)

Collecting networkx&gt;=1.8 (from scikit-image)

Downloading https://files.pythonhosted.org/packages/11/42/f951cc6838a4dff6ce57211c4d7f8444809ccbe2134179950301e5c4c83c/networkx-2.1.zip (1.6MB)

Collecting cloudpickle&gt;=0.2.1 (from scikit-image)

Downloading https://files.pythonhosted.org/packages/3e/41/cf788c011bff0ccf651fea2014450547213a03b3535a0f1bf813bf119aaf/cloudpickle-0.5.5-py2.py3-none-any.whl

Requirement already satisfied: numpy&gt;=1.11.0; extra == &quot;array&quot; in d:\slicer 4.9.0-2018-08-31\lib\python\lib\site-packages\numpy-1.13.1-py2.7-win-amd64.egg (from dask[array]&gt;=0.9.0-&gt;scikit-image) (1.13.1)

Collecting toolz&gt;=0.7.3; extra == &quot;array&quot; (from dask[array]&gt;=0.9.0-&gt;scikit-image)

Downloading https://files.pythonhosted.org/packages/14/d0/a73c15bbeda3d2e7b381a36afb0d9cd770a9f4adc5d1532691013ba881db/toolz-0.9.0.tar.gz (45kB)

Collecting decorator&gt;=4.1.0 (from networkx&gt;=1.8-&gt;scikit-image)

Downloading https://files.pythonhosted.org/packages/bc/bb/a24838832ba35baf52f32ab1a49b906b5f82fb7c76b2f6a7e35e140bac30/decorator-4.3.0-py2.py3-none-any.whl

Building wheels for collected packages: networkx, toolz

Running setup.py bdist_wheel for networkx: started

Running setup.py bdist_wheel for networkx: finished with status 'done'

Stored in directory: C:\Users\22374464\AppData\Local\pip\Cache\wheels\44\c0\34\6f98693a554301bdb405f8d65d95bbcd3e50180cbfdd98a94e

Running setup.py bdist_wheel for toolz: started

Running setup.py bdist_wheel for toolz: finished with status 'done'

Stored in directory: C:\Users\22374464\AppData\Local\pip\Cache\wheels\f4\0c\f6\ce6b2d1aa459ee97cc3c0f82236302bd62d89c86c700219463

Successfully built networkx toolz

Installing collected packages: toolz, dask, pillow, PyWavelets, decorator, networkx, cloudpickle, scikit-image

**The script skivi.exe is installed in 'D:\Slicer 4.9.0-2018-08-31\lib\Python\Scripts' which is not on PATH.**

Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Successfully installed PyWavelets-1.0.0 cloudpickle-0.5.5 dask-0.19.1 decorator-4.3.0 networkx-2.1 pillow-5.2.0 scikit-image-0.14.0 toolz-0.9.0

0

&gt;&gt;&gt;

Hi,
I was working on jupyter with scipy and suddenly it stoped working. What happened I dont know. it was importing before but not anymore

]:

import scipy

x

1

import scipy

Out[22]:

Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; File "D:\Slicer 4.9.0-2018-08-31\lib\Python\Lib\site-packages\scipy\__init__.py", line 77, in &lt;module&gt; from . import _distributor_init ImportError: cannot import name _distributor_init

I successfully installed scipy used it once but now its not working:

from pip._internal import main as pipmain

&gt;&gt;&gt; pipmain(['install','scipy'])

Requirement already satisfied: scipy in d:\slicer 4.9.0-2018-08-31\lib\python\lib\site-packages (1.1.0)

Requirement already satisfied: numpy&gt;=1.8.2 in d:\slicer 4.9.0-2018-08-31\lib\python\lib\site-packages\numpy-1.13.1-py2.7-win-amd64.egg (from scipy) (1.13.1)

0

&gt;&gt;&gt; import scipy

Traceback (most recent call last):

File &quot;&lt;console&gt;&quot;, line 1, in &lt;module&gt;

File &quot;D:\Slicer 4.9.0-2018-08-31\lib\Python\Lib\site-packages\scipy\__init__.py&quot;, line 77, in &lt;module&gt;

from . import _distributor_init

ImportError: cannot import name _distributor_init

Currently, you cannot import scipy into Slicer’s embedded Python interpreter. You have access to many Python libraries, you can use numpy, you can run a Jupyter kernel in Slicer’s Python interpreter, import native Python libraries, etc. but not import entire scipy.

Probably we can make Slicer’s Python interpreter compatible with all Python packages, including scipy, within 4-6 months.

Hi,
I need official packages of python. If I switch to ubuntu. will I be able to install any official package? is there anything I cant do in slicer on linux as compared to widows.

I am not sure of switching but without official packages (scipy, scikit-image, skfuzzy etc) I am unable to proceed with my work. Any option if I stay in windows and can still install official packages.

Thank you

Regards,
Saima Safdar