# Connect Slicer's built-in Python to Python IDE

**URL:** https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046
**Category:** Development
**Tags:** python
**Created:** [August 17, 2020, 4:53pm UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046 "2020-08-17T16:53:17Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![kleingeo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kleingeo/32/6772_2.png) [@kleingeo](https://discourse.slicer.org/u/kleingeo)
#### Post date: [August 17, 2020, 4:53pm UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/1 "2020-08-17T16:53:18Z")

</div>

I am trying to play around with a bunch of packages with Slicer, some of which are called through the command line/terminal. To make my life easier, I’m trying to connect the build-in python interpreter with Slicer to the IDE I use (PyCharm). I connected the the IDE to the `PythonSlicer.exe` file. However, when running anything I am getting this error.

```python
ModuleNotFoundError: No module named 'PythonQt'

```

Is there something I am missing?

The reason I am not using the normal remote debugger is that the file I am working with is run through cmd/terminal.

---

<div class="post-metadata">

### Author: ![ROSENty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rosenty/32/13334_2.png) [@ROSENty](https://discourse.slicer.org/u/ROSENty)
#### Post date: [December 2, 2021, 12:18pm UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/2 "2021-12-02T12:18:30Z")

</div>

I get the same error, is anybody can help me? 😭

---

<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: [December 2, 2021, 6:38pm UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/3 "2021-12-02T18:38:19Z")

</div>

You need to connect to a running application instance to access PythonQt and any objects that the Slicer application instantiates.

You can find instructions for connecting your IDE to Slicer [here](https://slicer.readthedocs.io/en/latest/developer_guide/debugging/overview.html#python-debugging).

To experiment with Python scripting in Slicer’s Python environment you can also [use Slicer as a Jupyter notebook kernel](https://github.com/Slicer/SlicerJupyter#slicerjupyter).

---

<div class="post-metadata">

### Author: ![ROSENty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rosenty/32/13334_2.png) [@ROSENty](https://discourse.slicer.org/u/ROSENty)
#### Post date: [December 3, 2021, 2:37am UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/4 "2021-12-03T02:37:51Z")

</div>

Thanks for your reply! 😋  
I just want to execute python script on terminal, but I used the '…/Slicer-4.11.20210226-linux-amd64/bin/PythonSlicer xx.py ', which is wrong. When I use ‘…/Slicer-4.11.20210226-linux-amd64 --python-script xx.py’, I get the correct result.

---

<div class="post-metadata">

### Author: ![ROSENty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rosenty/32/13334_2.png) [@ROSENty](https://discourse.slicer.org/u/ROSENty)
#### Post date: [December 3, 2021, 2:53am UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/5 "2021-12-03T02:53:32Z")

</div>

sorry, the correct way is '…/Slicer-4.11.20210226-linux-amd64/Slicer --python-script xx.py’

---

<div class="post-metadata">

### Author: ![ROSENty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rosenty/32/13334_2.png) [@ROSENty](https://discourse.slicer.org/u/ROSENty)
#### Post date: [December 16, 2021, 9:51am UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/6 "2021-12-16T09:51:03Z")

</div>

dear Lasso, I got another problem: when I execute python script on terminal on ubuntu, which works. But when I use SSH to connect ubuntu on another PC(windows) , and execute the same python script on terminal with same code

```auto
…/Slicer-4.11.20210226-linux-amd64 --python-script xx.py --no-main-window

```

, I got

```auto
qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

```

please help me, thanks a lot 😭 😭 😭

---

<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: [December 16, 2021, 5:58pm UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/7 "2021-12-16T17:58:18Z")

</div>

You need a frame buffer to run Slicer. If you search for topics in the forum about running Slicer on a headless machine then you will find more details (as far as I remember xdummy and xvfb-run may help).

---

<div class="post-metadata">

### Author: ![ROSENty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rosenty/32/13334_2.png) [@ROSENty](https://discourse.slicer.org/u/ROSENty)
#### Post date: [December 17, 2021, 1:27pm UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/8 "2021-12-17T13:27:22Z")

</div>

emmm, to be honest, I did what you said above, maybe I’m a newbie, I don’t get the correct way to solve this problem.  
Actually my problem is same as this

> [@Converting DICOM to NRRD on Docker via a Python script](https://discourse.slicer.org/t/converting-dicom-to-nrrd-on-docker-via-a-python-script/21096):
>
> Hello, I would like to start off thanking all of you for the great work with 3D Slicer. It is truly a phenomenal piece of software! The issue we are having requires some description, so I will split this question into two main sections. 1) Setup I am working on a containerized application to perform some processing of DICOM images, and part of the pipeline involves first converting the DICOM files into an .nrrd file. Performing the conversion must be done via the 3D Slicer interface for a very…

But I want to convert RTStruct file to .vtp file, so I got the same error 😭 😭 😭

---

<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: [December 17, 2021, 3:23pm UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/9 "2021-12-17T15:23:49Z")

</div>

Running a Python script on docker or using a virtual frame buffer should work fine. Let’s continue the discussion in that other topic.

---

<div class="post-metadata">

### Author: ![ROSENty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rosenty/32/13334_2.png) [@ROSENty](https://discourse.slicer.org/u/ROSENty)
#### Post date: [December 17, 2021, 3:29pm UTC](https://discourse.slicer.org/t/connect-slicers-built-in-python-to-python-ide/13046/10 "2021-12-17T15:29:33Z")

</div>

Thanks for your reply!!! You can reply me in

> [@Converting DICOM to NRRD on Docker via a Python script](https://discourse.slicer.org/t/converting-dicom-to-nrrd-on-docker-via-a-python-script/21096/5):
>
> There’s a batch struct conversion script in SlicerRT that could be run in docker using a similar formula. Be aware that RTStruct can be a tricky format due to variable vendor compliance issues, but SlicerRT is generally good at handling most cases.

👍for all of you,cause I can’t image you developers could answer my question directly
