Connect Slicer's built-in Python to Python IDE

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.

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.

1 Like

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

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.

To experiment with Python scripting in Slicer’s Python environment you can also use Slicer as a Jupyter notebook kernel.


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

1 Like

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

1 Like

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

…/Slicer-4.11.20210226-linux-amd64 --python-script --no-main-window

, I got

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 :sob: :sob: :sob:

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).

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

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

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

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

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