Integrate pycharm and Slicer

Operating system: Arch Linux
Slicer version: newest
Expected behavior: working debugging, want to use imports in pycharm and code completion
Actual behavior: debugging doesn’t work, can’t import slicer or vtk or qt in pycharm (code completion)


I work 2 years with Slicer and I made some modules but I can’t never integrate pycharm and Slicer-SuperBuild with 100%. What should I do? Because when I add vtk, qt, slicer paths to pycharm interpreter path that doesn’t work. Is it possible? And I can’t run debugging process. When I click connect in Slicer(debugging plugin) then nothing happen: Slicer doesn’t freeze.
Can’t find any relevant tutorial in Internet. I appreciate any suggestion.

Thank you

Hello Darek,

I use PyCharm to debug Slicer on a daily basis. I run it on Windows, but I think it should work the same way, because python should be the same.
There are instructions on how to set up Slicer and PyCharm on the website of the DebuggingTools extension:
Some important steps to do before you can use the debugger:

  • In PyCharm, set up and start a “Python Remote Debug” server on localhost with a port number e.g. 5678
  • In Slicer specify the egg file of PyCharm in the Python Debugger module, and set the same port number
    If the connection is successful, you will see a note in the PyCharm debugger console. And break points should work after that (no need to restart anything).

Code completion usually doesn’t work in the PyCharm code editor main window. The reason is that some python modules are loaded in runtime, so there is no way for PyCharm to know at any time what python modules are available. But if you pause the program execution with a breakpoint, you can use the debugger console to type code, and code completion will work correctly. That is because PyCharm knows at that time what modules are currently loaded.

I hope this helps,