# Coupling not working from the interface with fatal python initfsencoding error

**URL:** <https://persalys.discourse.group/t/coupling-not-working-from-the-interface-with-fatal-python-initfsencoding-error/58>\
**Category:** Persalys usage\
**Created:** [June 15, 2021, 4:00pm UTC](https://persalys.discourse.group/t/coupling-not-working-from-the-interface-with-fatal-python-initfsencoding-error/58 "2021-06-15T16:00:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucduron](https://yyz2.discourse-cdn.com/free1/user_avatar/persalys.discourse.group/lucduron/32/17_2.png) [@lucduron](https://persalys.discourse.group/u/lucduron)\
**Post date:** [June 15, 2021, 4:00pm UTC](https://persalys.discourse.group/t/coupling-not-working-from-the-interface-with-fatal-python-initfsencoding-error/58/1 "2021-06-15T16:00:04Z")

</div>

Dear community,

I am new with Persalys (v9.0.3) and I am trying to develop a coupling with an hydraulic computation code on Windows for uncertainty quantification.

I sucessfully managed to have a coupling working on a **standalone persalys script** :

 ![2021-06-15 17_49_22-Sélection C__Windows_System32_cmd.exe](https://global.discourse-cdn.com/free1/uploads/persalys/original/1X/8dd7b18ee8f38c017fef2168245f28f9f3837b06.png)

But when I use the **Persalys interface** (and use the “Import Python…”), it fails with the following traceback:

```auto
>>> exec(open(u"C:/PROJETS/python/Stage-2021-M2-DS-Alloul/persalys/test_couplage.py", encoding="utf-8").read())
Traceback (most recent call last):
  File "<string>", line 53, in _exec
  File "C:\softs\Persalys\Lib\site-packages\openturns\coupling_tools.py", line 249, in execute
    raise RuntimeError('Command "' + cmd +
RuntimeError: Command "C:/softs/WinPython-64bits-3.7.4/python-3.7.4.amd64/python.exe C:/PROJETS/python/Crue10_tools/cli/crue10_run_and_post_from_modifications.py C:/PROJETS/python/Stage-2021-M2-DS-Alloul/persalys/Etu_CE2016_Conc/Etu_CE2016.etu.xml inputs.json Cc_P012_LE20160202 outputs.csv" returned exit code 3221226505:
Fatal Python error: initfsencoding: unable to load the file system codec
zipimport.ZipImportError: can't find module 'encodings'

Current thread 0x00002b24 (most recent call first):

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<string>", line 35, in <module>
  File "C:\softs\Persalys\Lib\site-packages\persalys\persalys.py", line 5334, in run
    return _persalys.PhysicalModelAnalysis_run(self)
RuntimeError: InternalException : Python exception:
Traceback (most recent call last):
  File "<string>", line 53, in _exec
  File "C:\softs\Persalys\Lib\site-packages\openturns\coupling_tools.py", line 249, in execute
    raise RuntimeError('Command "' + cmd +
RuntimeError: Command "C:/softs/WinPython-64bits-3.7.4/python-3.7.4.amd64/python.exe C:/PROJETS/python/Crue10_tools/cli/crue10_run_and_post_from_modifications.py C:/PROJETS/python/Stage-2021-M2-DS-Alloul/persalys/Etu_CE2016_Conc/Etu_CE2016.etu.xml inputs.json Cc_P012_LE20160202 outputs.csv" returned exit code 3221226505:
Fatal Python error: initfsencoding: unable to load the file system codec
zipimport.ZipImportError: can't find module 'encodings'

Current thread 0x00002b24 (most recent call first):

```

- Am I doing something wrong?
- Has someone already succeeded in defining a coupling from the Persalys interface on a Windows machine?

This error seems to be linked with a problem within the Persalys python environment/configuration.

For more details, please find hereafter my Persalys Python script :

> **Source: test\_couplage.py**
>
> ```python
> #!/usr/bin/env python
> # coding: utf-8
> 
> from __future__ import print_function
> import openturns as ot
> import persalys
> 
> etude = persalys.Study('etude')
> persalys.Study.Add(etude)
> Fk_DefautMin = persalys.Input('Fk_DefautMin', 30, 'Fk_DefautMin')
> Fk_DefautMaj = persalys.Input('Fk_DefautMaj', 15, 'Fk_DefautMaj')
> Y0 = persalys.Output('Y0', '')
> inputs = [Fk_DefautMin, Fk_DefautMaj]
> outputs = [Y0]
> steps = []
> input_files = []
> input_file0 = persalys.CouplingInputFile('C:/PROJETS/python/Stage-2021-M2-DS-Alloul/persalys/inputs.json')
> input_file0.setConfiguredPath('inputs.json')
> input_file0.setVariables(['Fk_DefautMin', 'Fk_DefautMaj'], ['@Fk_DefautMin', '@Fk_DefautMaj'], ['{}', '{}'])
> input_files.append(input_file0)
> resource_files = []
> output_files = []
> output_file0 = persalys.CouplingOutputFile('outputs.csv')
> output_file0.setVariables(['Y0'], ['St_RET150.39a;'], [0], [0], [0])
> output_files.append(output_file0)
> step0 = persalys.CouplingStep('C:/softs/WinPython-64bits-3.7.4/python-3.7.4.amd64/python.exe C:/PROJETS/python/Crue10_tools/cli/crue10_run_and_post_from_modifications.py C:/PROJETS/python/Stage-2021-M2-DS-Alloul/persalys/Etu_CE2016_Conc/Etu_CE2016.etu.xml inputs.json Cc_P012_LE20160202 outputs.csv', input_files, resource_files, output_files)
> step0.setIsShell(True)
> steps.append(step0)
> modele_couplage = persalys.CouplingPhysicalModel('modele_couplage', inputs, outputs, steps)
> modele_couplage.setCleanupWorkDirectory(True)
> modele_couplage.setCacheFiles('', '')
> etude.add(modele_couplage)
> values = [30, 15]
> evaluation_0 = persalys.ModelEvaluation('evaluation_0', modele_couplage, values)
> evaluation_0.run()
> outputValues = evaluation_0.getResult().getDesignOfExperiment().getOutputSample()
> print(outputValues)
> etude.add(evaluation_0)
> 
> ```

Thank you in advance.

PS : Special thanks for Mathieu C. for making me aware of Persalys ([http://www.opentelemac.org/index.php/kunena/other/13168-openturns-gui-outsite-salome-hydro](http://www.opentelemac.org/index.php/kunena/other/13168-openturns-gui-outsite-salome-hydro)).

Best Regards,  
Luc

---

<div class="post-metadata">

**Author:** ![jschueller](https://yyz2.discourse-cdn.com/free1/user_avatar/persalys.discourse.group/jschueller/32/6_2.png) [@jschueller](https://persalys.discourse.group/u/jschueller)\
**Post date:** [June 16, 2021, 8:58am UTC](https://persalys.discourse.group/t/coupling-not-working-from-the-interface-with-fatal-python-initfsencoding-error/58/2 "2021-06-16T08:58:33Z")

</div>

Hello,

Persalys sets a few environment variables like PYTHONPATH to run its own python that may interfer with your winpython process, so you need to start your coupling process with its own env (eg via a script), or use persalys’s python interpreter instead.

---

<div class="post-metadata">

**Author:** ![lucduron](https://yyz2.discourse-cdn.com/free1/user_avatar/persalys.discourse.group/lucduron/32/17_2.png) [@lucduron](https://persalys.discourse.group/u/lucduron)\
**Post date:** [June 16, 2021, 12:28pm UTC](https://persalys.discourse.group/t/coupling-not-working-from-the-interface-with-fatal-python-initfsencoding-error/58/3 "2021-06-16T12:28:37Z")

</div>

Hello,

Thank you for your answer, the problem comes indeed from a Python configuration conflict.

I modified the coupling step of Persalys in using a **bat script** :

```python
step0 = persalys.CouplingStep('C:/PROJETS/python/Stage-2021-M2-DS-Alloul/persalys/test_couplage.bat', input_files, resource_files, output_files)

```

And this bat script **sets the different environment variables** :

```auto
@echo off

set PYTHONHOME=C:\softs\WinPython-64bits-3.7.4\python-3.7.4.amd64
set PATH=%PYTHONHOME%
set PYTHON=%PYTHONHOME%\python.exe
set PYTHONPATH=C:\PROJETS\python\Crue10_tools

%PYTHON% %PYTHONPATH%\cli\crue10_run_and_post_from_modifications.py C:\PROJETS\python\Stage-2021-M2-DS-Alloul\persalys\Etu_CE2016_Conc\Etu_CE2016.etu.xml inputs.json Cc_P012_LE20160202 outputs.csv

```

Hope it might help other users, my problem is now solved.

Regards,  
Luc
