# Running Slicer from PyCharm/external

**URL:** <https://discourse.slicer.org/t/running-slicer-from-pycharm-external/37095>\
**Category:** Development\
**Tags:** python\
**Created:** [June 29, 2024, 4:35am UTC](https://discourse.slicer.org/t/running-slicer-from-pycharm-external/37095 "2024-06-29T04:35:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![b\_srf](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@b\_srf](https://discourse.slicer.org/u/b_srf)\
**Post date:** [June 29, 2024, 4:35am UTC](https://discourse.slicer.org/t/running-slicer-from-pycharm-external/37095/1 "2024-06-29T04:35:09Z")

</div>

Hello! I want to run a python script for Slicer from PyCharm. I’m using the SegmentEditor module and PyRadiomics, and would like to automate the process for batch processing.

I’m able to write a script that runs on Slicer’s python console but I can’t figure out how to run it from PyCharm. I’m aware slicer has a debugger on pycharm and I tried setting slicer’s python.exe as the interpreter in pycharm. It hasn’t worked for me. Would anyone be able to advise?

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [June 29, 2024, 4:43am UTC](https://discourse.slicer.org/t/running-slicer-from-pycharm-external/37095/2 "2024-06-29T04:43:41Z")

</div>

Is there a reason you want to do this from PyCharm? This sounds more suitable for Jupyter notebooks?

See [GitHub - Slicer/SlicerJupyter: Extension for 3D Slicer that allows the application to be used from Jupyter notebook](https://github.com/Slicer/SlicerJupyter)

---

<div class="post-metadata">

**Author:** ![rfenioux](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rfenioux/32/70007_2.png) [@rfenioux](https://discourse.slicer.org/u/rfenioux)\
**Post date:** [July 1, 2024, 10:18am UTC](https://discourse.slicer.org/t/running-slicer-from-pycharm-external/37095/3 "2024-07-01T10:18:18Z")

</div>

The python interpreter of slicer can’t run on its own, you need the slicer environment if you use the modules and/or the slicer API.

You can run a python script in the slicer environment using this command :  
`Slicer.exe --python-script "/full/path/to/myscript.py" --no-splash --no-main-window`

I haven’t tried but you can probably configure pycharm to execute this command for you if you want to stay in pycharm.

---

<div class="post-metadata">

**Author:** ![b\_srf](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@b\_srf](https://discourse.slicer.org/u/b_srf)\
**Post date:** [July 3, 2024, 6:59pm UTC](https://discourse.slicer.org/t/running-slicer-from-pycharm-external/37095/4 "2024-07-03T18:59:33Z")

</div>

Thank you for the suggestions! I was able to do what I needed with Jupyter. I wanted to do it on PyCharm since it was what I was familiar with.

---

<div class="post-metadata">

**Author:** ![b\_srf](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@b\_srf](https://discourse.slicer.org/u/b_srf)\
**Post date:** [July 4, 2024, 8:00pm UTC](https://discourse.slicer.org/t/running-slicer-from-pycharm-external/37095/5 "2024-07-04T20:00:08Z")

</div>

I ran into a problem with my code. Below is a snippet. When I want to export the features table, the csv is empty; it just has the headers. I think this is because the feature extractor is not done working and the table is already exported as csv, because when I wait for the extracted to be done then save as table, it works fine. However, this won’t be good if I have to do this for every time I extract the features. Can you by any chance advise how to go about this?

```auto
inputSeg = slicer.util.getNode("Segmentation")
radiomicsModule = slicer.modules.SlicerRadiomicsWidget
radiomicsModule.inputVolumeSelector.setCurrentNode(volNode)
radiomicsModule.inputMaskSelector.setCurrentNode(inputSeg)
radiomicsModule.manualCustomizationRadioButton.setChecked(True)

#firstorder feature selected by default

radiomicsModule.onApplyButton()

outputTableNode = radiomicsModule.outputTableSelector.currentNode()
outputFilePath = r"path to file"
slicer.util.saveNode(outputTableNode, outputFilePath)

```
