I am facing a similar issue, I do not understand what is the answer here. Can someone please explain. I am using an ubuntu 22.04 with Sofa v23.06 and sofapython3 in-tree installation. my bashrc has these lines
export PATH="/usr/local/bin:$PATH"
export PATH=/home/sun/sofa/build/bin:/home/sun/.local/bin:/usr/bin/python3:$PATH
export PYTHONPATH=/home/sun/sofa/build/applications/plugins/SofaPython3:$PYTHONPATH
export SOFA_ROOT=/home/sun/sofa/build:$SOFA_ROOT
When I run a python on terminal I get this error

but when I just run
./sofa/build/bin/runSofa ../../Documents/Tumor_under_skin_research/Simulation/Vein_dVRK_SOFA_simulation-Lab_Training/Simulation_scene_development/Simulation_v6_RSSFF_DAL.py
I am able to run it properly, but my issue is I need to run by python3.
I tried sourcing manually in the terminal export SOFA_ROOT=~/sofa/build and then running again but I get this error now

Please Kindly Help