Vscode setting for Salome?

Hi,
do someone manage to setup VScode to access Salome API? I mean to have acces to the prototype and docs of methods.

I cannot get Pylance to find “import salome” even when I try to add PYTHONPATH to python.analysis.extraPaths

Best

Development concerning this is underway. In the meantime, here’s a tested solution (Ubuntu 24.04) that I use and which might help you. In addition, hovering over a method will also bring up a help pop-up…

  • First, edit SALOME launcher and move the following block to the end, just before # [APPLI variables] . Moving to the end is needed otherwise, SALOME won’t run.
    #[SALOMEBOOTSTRAP]
    context.setVariable(r"SALOMEBOOTSTRAP_ROOT_DIR", out_dir_Path + r"/BINARIES-UB24.04/SALOMEBOOTSTRAP", overwrite=True)
    context.setVariable(r"SALOME_APPLICATION_DIR", out_dir_Path + r"/BINARIES-UB24.04/SALOMEBOOTSTRAP", overwrite=True)
    context.addToPythonPath(out_dir_Path + r"/BINARIES-UB24.04/SALOMEBOOTSTRAP/__SALOME_BOOTSTRAP__")
    context.addToPythonPath(out_dir_Path + r"/BINARIES-UB24.04/SALOMEBOOTSTRAP/__RUN_SALOME__/lib/salome")
    context.addToLdLibraryPath(out_dir_Path + r"/BINARIES-UB24.04/SALOMEBOOTSTRAP/__RUN_SALOME__/lib/salome")

    #[KERNEL]
    context.setVariable(r"KERNEL_ROOT_DIR", out_dir_Path + r"/BINARIES-UB24.04/KERNEL", overwrite=True)
    context.addToPath(r"${KERNEL_ROOT_DIR}/bin/salome")
    context.addToLdLibraryPath(r"${KERNEL_ROOT_DIR}/lib/salome")
    context.addToPythonPath(r"${KERNEL_ROOT_DIR}/bin/salome")
    context.addToPythonPath(r"${KERNEL_ROOT_DIR}/lib/salome")
    context.addToPythonPath(r"${KERNEL_ROOT_DIR}/${PYTHON_LIBDIR}/salome")
  • Ensure that __init__.py is present, if not, create it:
cd SALOME-9.14.0-native-UB24.04-SRC
for d in $(find . -name salome -type d); do if [[ $(dirname $d) == *site-packages* ]]; then if [ ! -f $d/__init__.py ]; then touch $d/__init__.py; fi; fi; done

  • Create a .env file containing PYTHONPATH
PYTHONPATH=;for d in $(find . -name salome -type d); do if [[ $(dirname $d) == *site-packages* ]]; then if [  -f $d/__init__.py ]; then PYTHONPATH+="$PWD/$d:"; fi; fi; done; echo PYTHONPATH=$PYTHONPATH > .env
  • Edit settings.json (File :arrow_right: Preferences :arrow_right: Settings ) and add:
    "workbench.settings.applyToAllProfiles": ["python.envFile"], # optional 
    "python.envFile": "${workspaceFolder}/.env", # here you can also set a full path
  • Restart VSCode.
  • Open the SALOME binary directory.
  • Create a python script and start typing. Completion should work.

We are currently investigating why this hack about moving the KERNEL section to the end is required.
HTH

2 Likes