Using python salome libraries from a python IDE

Hello,

essentially, for Windows, you have to do the following:

  1. Open CMD

  2. In CMD go to SALOME directory.

  3. Run env_launch.bat
    Simply type env_launch.bat and press enter

  4. Run sublime text from the same CMD. This means you have to write the full path to the sublime text binary:
    For instance:
    >"c:\Program Files\Sublime Text\sublime_text.exe"
    With this the SALOME environment will be visible to Sublime Text.

  5. Now you also have to add a new Python build (Tools → Build System → New Build System), so that sublime text will launch the SALOME python interpreter instead of system python (causing “fatal cannot import site” errors)

    In the bellow build example, change the path to the python exe accordingly. I named my SALOME python build as SALOME_PYTHON

{
“cmd”: [“f:/SALOME-9.8.0/W64/Python/python.exe”, “-u”, “$file”],
“file_regex”: “[1]File "(…?)", line ([0-9]*)”,
“selector”: “source.python”
}

  1. Now select the new python build in the menu Tools → Build System → SALOME_PYTHON
  2. Write a new python script, try to import salome and it should work. Happy coding

I must say in Linux it’s much easier, just source the env_launch.sh and run sublime text and that’s it. Additionally if you install LSP and LSP-pyright, you can enjoy type hinting and code completion for functions (although sometimes it takes a while for pyright to analyze everything).

Best regards,
Gregor


  1. ↩︎

2 Likes