Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

zadravecm
New Contributor II

Execute python script in load script

Hi,

I am trying to run python script inside my load script in Qlik Sense app.

I know that I need to put OverrideScriptSecurity=1 in Settings.ini

I put

Execute py lib://python/getSolution.py 12 'ble';

and I get no error in qlik sense, bu script is not executed (I think) because inside the script I have

f = open("file.xml", "wb")

f.write(xml)

f.close

and file is not saved.

If I run script from terminal, then script is properly executed.

What could go wrong?

16 Replies

Re: Execute python script in load script

Can you specify a full path to the python interpreter?

zadravecm
New Contributor II

Re: Execute python script in load script

Hi,

My path is

C:\Users\Marko Z\AppData\Local\Programs\Python\Python37-32\python.exe

why? Is there a "right" and "wrong" path for qlik sense?

Re: Execute python script in load script

You misunderstood me. I meant "can you add a full path to the command you are trying to execute using the EXECUTE script statement".

Most of these EXECUTE problems have to do with the fact that the Windows shell can't find the program to execute. Even cmd.exe may require a full path sepcification before it can be found.

zadravecm
New Contributor II

Re: Execute python script in load script

hmmm I can see your point...

Now I try with :

Set vPythonPath = "C:\Users\Marko Z\AppData\Local\Programs\Python\Python37-32\python.exe";

Set vPythonFile = "C:\Users\Marko Z\Documents\Qlik\Sense\....\getSolution.py";

Execute $(vPythonPath) $(vPythonFile);

But it still doesn't work...

any idea?

zadravecm
New Contributor II

Re: Execute python script in load script

Is there a way that python would writ in console... so that I would see if it is executing.... I see that if I mistype the path Qlik Sense give me an error

The handle is invalid:,.....

Is this mean that if no error presents, that script is executed? But why then it would not save a file,...

Re: Execute python script in load script

No idea. Permssions? Can you check whether you python script - when launched via the EXECUTE statement - is able to write to a global directory like C:\Temp?

zadravecm
New Contributor II

Re: Execute python script in load script

I am not sure what do you mean by that,... I am sure that Qlik Sense could save file (I exported csv file), but I can't check if python has permissions because the it doesn't display any error. Terminal could save to file,..

zadravecm
New Contributor II

Re: Execute python script in load script

My python code is

    xml = "Marko"

    xml = xml.encode('utf-8')

    f = open("C:\\Users\\Marko Z\\Test.xml", "wb")

    f.write(xml)

    f.close

Re: Execute python script in load script

Indeed, your attempt to write a file seems straightforward enough. What I meant by my request was to try to write to a global directory that is accessible to everyone (like C:\Temp)

If you start ProcessExplorer or Task Manager, do you see the python interpreter being launched when you run the load script? For a better chance of python.exe being visualized, add some code to your script that takes a while to complete, like a loop.

Community Browser