Basic PyCharm Importation Analysis for Slicer Development

After searching the web, I found that it is not currently possible to gain full IDE code-completion/analysis for Slicer python development as some packages are added at run-time.

I was able to gain some package importation analysis (resulting in the removal of many false errors and warnings) by the following:

  1. In PyCharm open your Slicer project of choice
  2. In the menu-bar, open File > Settings
  3. In Settings, click Project: ____ > Project Interpreter
  4. Next to Project Interpreter click :gear: > Add
  5. Navigate to and select Slicer installation directory \ bin \ PythonSlicer.exe

The following should appear:
image
PyCharm will now interpret using Slicer’s included python binary. I would not recommend updating or adding packages. However, I did find it useful to add the Python 2.7 PyQt package as a reference module, as it offers full PyQt code-completion. Remembering to remove this manually added package and point to Slicer’s PyQt (import qt) before deployment.

3 Likes

As a clarification, Slicer uses PythonQt and not PyQt. They are similar, but if you run into python related Qt issues make sure to look into the correct source. Slicer uses PythonQt as included in CTK https://github.com/commontk/PythonQt.

2 Likes