Coupling not working from the interface with fatal python initfsencoding error

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 :

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

>>> 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
#!/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).

Best Regards,
Luc

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.

1 Like

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:

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:

@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

2 Likes