How to import cx_Oracle library into python SikuliX script --- not possible (C-based) --- workaround

Asked by ANTONIO CARLOS PAES NASCIMENTO

******************* workarounds

see comment #3 following

----------------------------------------------------
Hi guys,

I'm trying to import cx_Oracle library into my python test script inside sikulix, however I'm getting this error:

[error] script [ connect_and_print ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "C:\Users\BRX Retail\Desktop\Testes_automatic\connect_and_print.sikuli\connect_and_print.py", line 3, in <module> import cx_Oracle ImportError: No module named cx_Oracle

My imports are:

import random
import org.sikuli.script.SikulixForJython
import cx_Oracle

Can you guys help me?

Thanks,

Antonio

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Supposing the module cx_Oracle is in a place, where it can be found by SikuliX (containing folder is in sys.path).

Sorry, but since SikuliX is Java based using the Jython interpreter, only Python modules written in plain Python language can be imported.

cx_Oracle seems to depend on native libraries, which means it contains C-based code, which leads to the ImportError: No module named cx_Oracle

Revision history for this message
ANTONIO CARLOS PAES NASCIMENTO (antonio.paes) said :
#2

Hi RaiMan,

First off all thanks for answering.

And if I use another dev tool like Sublime and try to import sikulix inside that tool, or something in this line?

Thanks.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

cx_Oracle only works with Python (C-based Python), but from there you cannot use SikuliX directly, but only with some Python-Java wrapping (like pyjnius).

So if you need direct access to your DB during scriptrun, then it will be a stony way - may be impossible.

If acceptable: write what you need from your DB to a CSV-file and use that in your script.

Surely there might be other workarounds, like running Python scripts from SikuliX using subprocess, that return some stuff to be used in the script.

Revision history for this message
ANTONIO CARLOS PAES NASCIMENTO (antonio.paes) said :
#4

Thanks man,

I found this question https://answers.launchpad.net/sikuli/+question/286612 and I think this solve my problem, however when I run rour example I got this errors in the message area from sikulix IDE:

[error] Error caused by: Traceback (most recent call last): File "C:\Users\BRX Retail\Desktop\Testes_automatic\test)open_app.sikuli\test)open_app.py", line 4, in <module> result = run(cmd) File "C:\Users\BRX Retail\AppData\Roaming\Sikulix\Lib\sikuli\Sikuli.py", line 555, in run return Sikulix.run(cmd) at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at org.sikuli.basics.Debug.log(Debug.java:726)
at org.sikuli.basics.Debug.logx(Debug.java:691)
at org.sikuli.script.RunTime.log(RunTime.java:97)
at org.sikuli.script.RunTime.runcmd(RunTime.java:2952)
at org.sikuli.script.Sikulix.run(Sikulix.java:550)
at org.sikuli.script.Sikulix.run(Sikulix.java:546)
at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
at sun.reflect.D

elegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.util.UnknownFormatConversionException: java.util.UnknownFormatConversionException: Conversion = '1'

This is my script:

python = r"C:\Users\BRX Retail\AppData\Local\Programs\Python\Python38-32\"
pyscript = r"C:\Users\BRX Retail\Desktop\teste.py"
cmd = "%s %s" % (python, pyscript)
result = run(cmd)
print(result)

#teste.py

import cx_Oracle

# Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
con = cx_Oracle.connect('user/passwd@host')

#cursor = con.cursor()
#cursor.execute("""
# SELECT *
# FROM table
# """)

#res = cursor.fetchmany(numRows=10)

print("BLABLA")

You already see this?

Thanks

Revision history for this message
RaiMan (raimund-hocke) said :
#5

python = r"C:\Users\BRX Retail\AppData\Local\Programs\Python\Python38-32\"

... a raw string can not end with a \

try:
python = r"C:\Users\BRX Retail\AppData\Local\Programs\Python\Python38-32"

Revision history for this message
ANTONIO CARLOS PAES NASCIMENTO (antonio.paes) said :
#6

Nice!

It works, but now we've permission problems:

[error] RunTimeIDE: fatal error: java.io.IOException: Cannot run program "C:\Users\BRX Retail\AppData\Local\Programs\Python\Python38-32": CreateProcess error=5, Acesso negado
9999
*****error*****
java.io.IOException: Cannot run program "C:\Users\BRX Retail\AppData\Local\Programs\Python\Python38-32": CreateProcess error=5, Acesso negado*****error*****

The strage is all this folders are with full permissions.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#7

Add an extension?

.exe?

Revision history for this message
ANTONIO CARLOS PAES NASCIMENTO (antonio.paes) said :
#8

Good one hahah

Now it works, thanks RaiMan (:

I'll close this question!

Revision history for this message
ANTONIO CARLOS PAES NASCIMENTO (antonio.paes) said :
#9

Thanks RaiMan, that solved my question.