# Python interpreter arguments containing special characters

**URL:** https://discourse.slicer.org/t/python-interpreter-arguments-containing-special-characters/33466
**Category:** Support
**Created:** [December 20, 2023, 9:53am UTC](https://discourse.slicer.org/t/python-interpreter-arguments-containing-special-characters/33466 "2023-12-20T09:53:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![aymeric.chataigner](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aymeric.chataigner/32/4977_2.png) [@aymeric.chataigner](https://discourse.slicer.org/u/aymeric.chataigner)
#### Post date: [December 20, 2023, 9:53am UTC](https://discourse.slicer.org/t/python-interpreter-arguments-containing-special-characters/33466/1 "2023-12-20T09:53:15Z")

</div>

Hi,

It is probably not a classic use of the python interpreter embedded in 3D Slicer but I would like to inform you about this strange behavior:

I use this interpreter to run a script which requires a file path as parameter.  
If the path contains some special characters (like é or €) which requires utf-8 encoding then sys.argv is wrong: these characters are replaced by other ones.

Here is a small script which shows clearly the issue:

```auto
import sys
import os

param = sys.argv[1]
print('param = ' + param)

argvb = list(map(os.fsencode, sys.argv))
param_bytes = argvb[1]
print('param_bytes = ' + str(param_bytes))

```

As you guess you have to provide 1 parameter to run it:  
/path/to/slicer/install/bin/PythonSlicer €

Result:  
param = Ã©  
param\_bytes = b’\xc3\x83\xc2\xa9’

Expected Result (running ubuntu embedded python3 interpreter)  
param = é  
param\_bytes = b’\xc3\xa9’

We see \x83\xc2 is added to the bytes, and it is caused by a wrong double utf-8 encoding issue (the accepted answer works well):

> <https://stackoverflow.com/questions/4267019/double-decoding-unicode-in-python>

Do you have any idea why the python interpreter of 3d slicer decodes parameters twice ?

Best regards

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 21, 2023, 2:31pm UTC](https://discourse.slicer.org/t/python-interpreter-arguments-containing-special-characters/33466/2 "2023-12-21T14:31:39Z")

</div>

Thanks for reporting. The issue is known, it is caused by a bug in the application launcher. I’ve submitted a fix some time ago:

> <https://github.com/commontk/AppLauncher/pull/127>
>
> Should fix the issues described here: https://discourse.slicer.org/t/slicer-igno…ring-command-line-path-with-accents/24569

It would be great if you could work with @jcfr to get the fix integrated.

Until then you can use a workaround: start bash using the launcher and then start Slicer from that terminal.

```plaintext
./Slicer --launch bash
bin/SlicerApp-real --python-code "print('é')"

```

---

<div class="post-metadata">

### Author: ![aymeric.chataigner](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aymeric.chataigner/32/4977_2.png) [@aymeric.chataigner](https://discourse.slicer.org/u/aymeric.chataigner)
#### Post date: [December 22, 2023, 10:08am UTC](https://discourse.slicer.org/t/python-interpreter-arguments-containing-special-characters/33466/3 "2023-12-22T10:08:40Z")

</div>

Thank you Andras for this quick answer, I will discuss it with @jcfr

---

<div class="post-metadata">

### Author: ![aymeric.chataigner](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aymeric.chataigner/32/4977_2.png) [@aymeric.chataigner](https://discourse.slicer.org/u/aymeric.chataigner)
#### Post date: [January 3, 2024, 2:21pm UTC](https://discourse.slicer.org/t/python-interpreter-arguments-containing-special-characters/33466/4 "2024-01-03T14:21:49Z")

</div>

Another quick question: why is there no completion in this interpreter ?
