Personal tools
You are here: Home Forum Use Debugging a salome script with a python IDE

Debugging a salome script with a python IDE

Up to Use

Debugging a salome script with a python IDE

Posted by Miguel Segade at April 21. 2020

Hi

I am developing some salome python scripts and I it will be very helpful to run them through a python IDE, specially for debugging purposes. This user tried the same, but without success:

https://www.salome-platform.org/forum/forum_10/130992364

I tried setting a virtual enviroment from within a salome shell session, and also exporting LD_LIBRARY_PATH PYTHONPATH in the activate script. But when using it in the IDE (visual studio code),  I get a "Naming Service Unreacheable" error which I cannot solve.

Is there any way to set this up correctly? Any other way to use an IDE to debug python salome code?

Thanks

Re: Debugging a salome script with a python IDE

Posted by Nabil Ghodbane at April 21. 2020

The following suggested solution works for me. Surely one SALOME expert will suggest a more robust approach, but here is what you can do (tested on CentOS 7, not tried for other distributions)

  • install code which is for instance installed in /usr/bin/code
  • edit file SALOME-9.4.0-CO7-SRC/BINARIES-CO7/GUI/share/salome/plugins/gui/demo/salome_plugins.py
  • in that file, search for runSalomeShellSession and replce:

if os.path.exists("/usr/bin/gnome-terminal"):

      command = 'gnome-terminal -t "SALOME %s - Shell session" -e "%s/salome shell" &'%(version,kernel_appli_dir)

 
with:
    if os.path.exists("/usr/bin/code"):
      command = 'code'
    elif os.path.exists("/usr/bin/gnome-terminal"):
      command = 'gnome-terminal -t "SALOME %s - Shell session" -e "%s/salome shell" &'%(version,kernel_appli_dir)
  • launch SALOME
  • In the main menu bar, select Tools -> Plugins -> SALOME shell session
  • this will launch code
  • then you can run step by step your script
Attachments

Re: Debugging a salome script with a python IDE

Posted by Nabil Ghodbane at April 21. 2020

A cleaner approach. Download the enclosed file which:

  • adds a function which launches Visual studio code.
  • adds an entry :  Tools -> Plugins -> Launch Visual Studio Code

You need to copy this file to:

SALOME-9.4.0-*-SRC/BINARIES-*/GUI/share/salome/plugins/gui/demo/salome_plugins.py

You need to ensure that you have Visual Studio Code installed.

 

Attachments

Re: Debugging a salome script with a python IDE

Posted by Miguel Segade at April 22. 2020

That is very clever! I got it working on my pc.

Thank you!

Powered by Ploneboard
Document Actions