# Pyzmq in slicer python

**URL:** <https://discourse.slicer.org/t/pyzmq-in-slicer-python/587>\
**Category:** Support\
**Tags:** python\
**Created:** [June 28, 2017, 1:03pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587 "2017-06-28T13:03:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filipe\_Trocado\_Ferre](https://avatars.discourse-cdn.com/v4/letter/f/3be4f8/32.png) [@Filipe\_Trocado\_Ferre](https://discourse.slicer.org/u/Filipe_Trocado_Ferre)\
**Post date:** [June 28, 2017, 1:03pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587/1 "2017-06-28T13:03:45Z")

</div>

Operating system: Ubuntu 16  
Slicer version: 4.7  
Expected behavior:  
Actual behavior: Can’t Import pyzmq

Is there any way one could import pyzmq into slicer python module ? I want to process 3d scans in my python modules that I can’t install in slicer. At least communication support should be able to do.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 28, 2017, 1:07pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587/2 "2017-06-28T13:07:55Z")

</div>

Slicer can receive surfaces, volumes, transforms, etc. in real-time through [OpenIGTLink protocol](http://www.openigtlink.org). There are a couple of Python implementations of OpenIGTLink (I haven’t tried them, it would be great if you could try them and report back), so it would be probably much simpler to use that protocol instead. You can set up connections in OpenIGTLinkIF module.

---

<div class="post-metadata">

**Author:** ![Filipe\_Trocado\_Ferre](https://avatars.discourse-cdn.com/v4/letter/f/3be4f8/32.png) [@Filipe\_Trocado\_Ferre](https://discourse.slicer.org/u/Filipe_Trocado_Ferre)\
**Post date:** [June 28, 2017, 2:33pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587/3 "2017-06-28T14:33:01Z")

</div>

At first sight, None of these ([https://github.com/Danielhiversen/pyIGTLink](https://github.com/Danielhiversen/pyIGTLink) ; [https://github.com/nenetto/OpenIGTLink/tree/master/Notebooks](https://github.com/nenetto/OpenIGTLink/tree/master/Notebooks)) implement image sending and receiving using igtlink protocol.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [June 28, 2017, 2:48pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587/4 "2017-06-28T14:48:50Z")

</div>

The first one has an [example](https://github.com/Danielhiversen/pyIGTLink/blob/07cf0759f6a1901c008c945a6336c355c43f45f6/pyIGTLink/pyIGTLink.py#L483-L501) of sending a numpy array as an image message.

For zmq, recent Slicer nightly versions include pip, and should be able to download a pre-compiled (wheel) version. In the slicer python prompt: `import pip; pip.main(['install', 'PyZMQ'])`

That said, Andras’ suggestion is still better because:

- you need to very careful with the event loop among python, slicer, qt, etc. and this work has already been done for OpenIGTLink
- I’m not sure what the Slicer + wheel (pypi) compatibility level is across platforms. I believe there is/was at least one weird shared library compatibility issue on linux for pyradiomics.

---

<div class="post-metadata">

**Author:** ![Filipe\_Trocado\_Ferre](https://avatars.discourse-cdn.com/v4/letter/f/3be4f8/32.png) [@Filipe\_Trocado\_Ferre](https://discourse.slicer.org/u/Filipe_Trocado_Ferre)\
**Post date:** [June 28, 2017, 3:03pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587/5 "2017-06-28T15:03:01Z")

</div>

You’re right. I think i’ll have to mesh both implementation to achieve both send/receive images.  
Thank you both!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 28, 2017, 3:05pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587/6 "2017-06-28T15:05:20Z")

</div>

You cannot get precompiled binary python packages on Windows (Slicer uses Python 2.7 and VS2013).

It would be great if you could test these Python OpenIGTLink implementations. If you find a nice, promising one then we would be happy to help with fixing issues or extending it to additional message types, etc.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [June 28, 2017, 3:16pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587/7 "2017-06-28T15:16:36Z")

</div>

Be aware that the second implementation is [GPL licensed](https://en.wikipedia.org/wiki/GNU_General_Public_License), so you need to abide by the GPL provisions. Practically: any derived code must also be provided under GPL (there are many in-depth discussions on the internet of the implications).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 28, 2017, 3:31pm UTC](https://discourse.slicer.org/t/pyzmq-in-slicer-python/587/8 "2017-06-28T15:31:55Z")

</div>

Thanks for checking. I can only afford to spend time with code that we can use without restrictions, so it would be important to choose something based on BSD, MIT or similar license.
