# Access slicer modules and libraries in pycharm

**URL:** https://discourse.slicer.org/t/access-slicer-modules-and-libraries-in-pycharm/2765
**Category:** Support
**Created:** [May 6, 2018, 8:27pm UTC](https://discourse.slicer.org/t/access-slicer-modules-and-libraries-in-pycharm/2765 "2018-05-06T20:27:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hadasara](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@hadasara](https://discourse.slicer.org/u/hadasara)
#### Post date: [May 6, 2018, 8:27pm UTC](https://discourse.slicer.org/t/access-slicer-modules-and-libraries-in-pycharm/2765/1 "2018-05-06T20:27:15Z")

</div>

Hi,  
I’d like to know why when I try to call slicer modules\libraries (vtk, numpy), they are not recognized, unless I’m in the remote-debug mode, and run some loadable module, while there is a breakpoint somewhere in the code:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/a/5aee56f6a3bde3425b9987ec1381f0d8b0653b39.png)

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/5/5579590acf8383dae2823cd5052e3438c09b8fbb.png)

What path should I add to the python search path? and how it is different in the different modes?

Thanks!!

---

<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: [May 7, 2018, 1:58pm UTC](https://discourse.slicer.org/t/access-slicer-modules-and-libraries-in-pycharm/2765/2 "2018-05-07T13:58:41Z")

</div>

Slicer is not a Python interpreter extended by Python libraries, but an application that embeds Python. The difference is explained here: [https://docs.python.org/2/extending/embedding.html](https://docs.python.org/2/extending/embedding.html)

The consequence is that you cannot run Slicer from any generic Python interpreter, such as the one started by the PyCharm IDE. You can only load some of the libraries, such as VTK or SimpleITK into any Python interpreter (and it should not be too difficult to make the core MRML library and some other parts loadable as well). However, in general, to access all Slicer classes, you always need to start Slicer application and then connect to Slicer’s built-in Python interpreter.

---

<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: [May 15, 2018, 7:19pm UTC](https://discourse.slicer.org/t/access-slicer-modules-and-libraries-in-pycharm/2765/3 "2018-05-15T19:19:08Z")

</div>

> [@lassoan](#):
>
> it should not be too difficult to make the core MRML library and some other parts loadable as well

There may still be some other modules we need to exclude, but the following PR allows to safely `import slicer` in the regular python(.exe) binary included with Slicer:

> <https://github.com/Slicer/Slicer/issues/945>
>
> \_This issue was created automatically from an original \[Mantis Issue\](https://ma…ntisarchive.slicer.org/view.php?id=945). Further discussion may take place here.\_

However, note that the `python` binary must either be started from the launcher or from a shell with with the [necessary environment variables](https://discourse.slicer.org/t/python-real-different-from-python-interpreter/2496/5).

---

<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: [May 15, 2018, 7:38pm UTC](https://discourse.slicer.org/t/access-slicer-modules-and-libraries-in-pycharm/2765/4 "2018-05-15T19:38:11Z")

</div>

Thanks for the information @ihnorton, this will be very useful.

I see that some Slicer Qt widget modules had to be excluded. Do you know why they caused crash?

Can we still access MRML widgets and various custom Qt widgets defined in Slicer modules?

---

<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: [May 15, 2018, 7:54pm UTC](https://discourse.slicer.org/t/access-slicer-modules-and-libraries-in-pycharm/2765/5 "2018-05-15T19:54:31Z")

</div>

> [@lassoan](#):
>
> I see that some Slicer Qt widget modules had to be excluded. Do you know why they caused crash?

PythonQt shared libraries try to access `PythonQt::self` singleton (or something with a similar name) during shared library loading, but it is not initialized.

> Can we still access MRML widgets and various custom Qt widgets defined in Slicer modules?

No, right now anything Qt has to be excluded. There is a [discussion](https://sourceforge.net/p/pythonqt/discussion/631393/thread/ec93fba5/) on the PythonQt forum about what would be required to use PythonQt that way – we would need a wrapper shim that initializes PythonQt and sets up the event loop. For now my use-case is Python-based CLI.
