Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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?

17 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Just a question. Did you disable Standard Mode in Qlik Sense Desktop before trying to execute your Python script?

See: Disabling standard mode - Qlik Sense

Anonymous
Not applicable
Author

Yes I did.

Anonymous
Not applicable
Author

You were right. If I move script in C:\Windows\test.py it work.

Now I assume that the problem is space in path....

Any thoughts?

Thank you.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Put double-quotes around paths that you want to pass as-they-are (including any spaces) to an external program. Double-quotes will be passed along and won't be interpreted by the script engine in this case.

See this subthread for an explanation: Re: Double quotes on Execute statement

aritting
Creator
Creator

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.

Peter Cammaert's answer is most likely the correct one if you get the error message " Error: The handle is invalid."

Even if the execute command runs in QlikView Application on the server the executable may not be in the path for the service account running the qlikview distribution engine.

Check the system Path environment variable in Windows System Properties "Environment Variables"

Anonymous
Not applicable
Author

I guess the problem is not with spaces but the directory is not accessible from qlik sense.

jlongoria
Creator
Creator

This works for me.

 

I have the following folders/files:

myfolder/qvw/testpython.qvw

myfolder/bin/testpython.qvw

myfolder/data

 

For QVW:

Go to Settings-->User Preferences-->Security and select the checkbox next to "Script (Allow Database Write and Execute Statements)"

In the load script editor Settings tab, select the checkbox next to "Can Execute External Programs"

 

QVW Load Script:

//
// Change path to python.exe per your local installation
//
EXECUTE D:\ProgramData\Anaconda3\python.exe "..\bin\testpython.py"
 
 
Python file:
# Open a file stream for writing
# assume data folder exists...if not, need to create for this call to work
f = open("../data/testpython.txt","w+")
 
# Write test content to file
f.write("this is a test...this is only a test...")
 
# Close file stream
f.close()​
nategreen
Contributor III
Contributor III

I was able to get the below to work in qlik sense:
set vPyExe = C:\Program Files\Python37\python.exe;
set vPyScript = D:\...\PythonScript.py;

Execute
"$(vPyExe)" "$(vSource)"
;