# Issues when calling another python environment in a CLI module

**URL:** <https://discourse.slicer.org/t/issues-when-calling-another-python-environment-in-a-cli-module/21430>\
**Category:** Support\
**Tags:** extensions\
**Created:** [January 12, 2022, 11:52pm UTC](https://discourse.slicer.org/t/issues-when-calling-another-python-environment-in-a-cli-module/21430 "2022-01-12T23:52:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathieu\_Leclercq](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mathieu_leclercq/32/13767_2.png) [@Mathieu\_Leclercq](https://discourse.slicer.org/u/Mathieu_Leclercq)\
**Post date:** [January 12, 2022, 11:52pm UTC](https://discourse.slicer.org/t/issues-when-calling-another-python-environment-in-a-cli-module/21430/1 "2022-01-12T23:52:38Z")

</div>

Hello,  
I am developing an extension for Slicer that offers a GUI for runnning 3D surface segmentation. The GUI and the segmentation algorithm both work fine separately, but I need to call my own python environment in the extension code to start the process automatically. The idea is to execute in a scripted cli module a command with os.system() that runs the segmentation program in the right environment. I was able to make it work on a local environment on my machine, even when both python versions are different. But there are errors when trying to do it from Slicer’s Python. At first I had issues because \_\_sysconfingdata\_\_linux\_x86\_64-linux-gnu.py file was missing. I followed the instructions written on page 394 of [3D Slicer documentation](https://readthedocs.org/projects/slicer/downloads/pdf/latest/), but now the error that I get is “AssertionError: SRE module mismatch”. I added a wrapper script (bash script) to try and fix the issue but I still get the same error:

> Traceback (most recent call last):  
> File “/path/to/segmentationfile/segmentation\_code.py”, line 16, in   
> import argparse  
> File “/tools/Slicer4/Slicer-4.13.0-2021-09-18-linux-amd64/lib/Python/lib/python3.6/argparse.py”, line 89, in   
> import re as \_re  
> File “/tools/Slicer4/Slicer-4.13.0-2021-09-18-linux-amd64/lib/Python/lib/python3.6/re.py”, line 123, in   
> import sre\_compile  
> File “/tools/Slicer4/Slicer-4.13.0-2021-09-18-linux-amd64/lib/Python/lib/python3.6/sre\_compile.py”, line 17, in   
> assert \_sre.MAGIC == MAGIC, “SRE module mismatch”  
> AssertionError: SRE module mismatch

As you can see python looks for argparse.py in the Slicer Python library, even though I explicitely provide another python path when executing the segmentation script.  
One thing to note is that I don’t have this issue when running the same command from my main scripted module. The script for the segmentation runs without error. However I need this to work through a CLI module in order for the GUI to not freeze while the script is running.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 13, 2022, 12:46am UTC](https://discourse.slicer.org/t/issues-when-calling-another-python-environment-in-a-cli-module/21430/2 "2022-01-13T00:46:36Z")

</div>

You can use [`slicer.util.launchConsoleProcess(args)`](https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/util.py#L3012-L3043) instead of `os.system` to use your native environment instead of the Slicer one.
