Description: I wrote macro in calc file,wrote python scrpit in macro directory. I executed the script add got error. error message from scriptforge is "NOSCRIPTERROR". But the script exists. Actual error is that the script imports library which is not exists. Steps to Reproduce: 1.create ods file and put macro bellow Sub Main GlobalScope.BasicLibraries.loadLibrary("ScriptForge") session = CreateScriptService("Session") sRange=session.ExecutePythonScript(session.SCRIPTISPERSONAL, "util.py$str_format", "{}{}:{}{}","A",1,"B",10) print(sRange) End Sub 2.create util.py C:\Users\_USER_\AppData\Roaming\LibreOffice\4\user\scripts\python\util.py import not_present #error def str_format(fmt,*params): s = fmt.format(*params) return s 3.run macro Actual Results: error message from scriptforge is bellow Error NOSCRIPTERROR x A Library: ScriptForge Service: Session Method: ExecutePythonScript Arguments: [Scope], Script, argO[, arg1] A serious error has been detected in your code on argument : « Script ». | The requested Python script could not be located in the given libraries and modules. « Scope » = user « Script » = util.py$strformat THE EXECUTION IS CANCELLED. Do you want to receive more information about the ‘ExecutePythonScript" method ? dom | DZD, Expected Results: error message from scriptforge is "IMPORTERROR". Reproducible: Always User Profile Reset: No Additional Info: Version: 25.8.4.2 (X86_64) Build ID: 290daaa01b999472f0c7a3890eb6a550fd74c6df CPU threads: 12; OS: Windows 11 X86_64 (build 26200); UI render: Skia/Raster; VCL: win Locale: ja-JP (ja_JP); UI: ja-JP Calc: threaded
Created attachment 205303 [details] error message
Created attachment 205304 [details] calc ods
Created attachment 205305 [details] python macro
Cannot reproduce the issue! Nevertheless, I would suggest avoiding ScriptForge and instead using: ``` sub call_python provider = thisComponent.getScriptprovider() script = provider.getScript("vnd.sun.star.script:util.py$str_format?language=Python&location=user") args = array("{}{}:{}{}","A",1,"B",10) print script.invoke(args, array(), array()) end sub ```
Created attachment 205332 [details] stacktrace errormessage on provoked ImportError from python
The ExecutePythonScript() method uses in the background the same UNO interfaces as the example in comment#4, i.e. - script = provider.getScript() - script.invoke() The error message which is considered in this bug report is related to the execution of getScript(). The major reasons for getScript() being unsuccessful are reflected in the message: either the file does not exist or the called [def] function is not found. The case in the example is different: it is a *compile* error: the import statement is indeed executed at module loading. It is rather unusual to run a Python script from Basic while it even does not compile stand alone. Compare with next variant. If you move the import statement to inside the function, the import is delayed up to the invoke() method. It fails - obvously - too. But it is now an *execution* error that is reported in detail in the error message displayed to the user, as would any other run-time error. The distinction in error reporting was made deliberately. It can nevertheless be reviewed. But, is it really relevant and useful to review it ? More comments welcome. Thanks for reporting the bug.