Python module: ImportError ( No module named psycopg2 ) --- not compatible with Jython or not on sys.path

Asked by Hina on 2018-09-07

I have updated PIP and installed psycopg2 module but when I run the code from sikukli with python it gives me this error message. I'm running Sikuli on windows 10.
Same code works fine as an independent python file.

import csv
import psycopg2
try:
 conn = psycopg2.connect(host='test5', database="TestDB", port="5432", user="postgres",password="test",options='-c search_path="users"')
 print "connection successful"

except:
 print "I am unable to connect to the database"
cur = conn.cursor()
cur.execute("SET search_path TO users")
cur.execute(""" SELECT * from "UserDetail" """)
rows = cur.fetchall()
print "\nShow me the data:\n"
for row in rows:
   print " ", row[0]
   print " ", row[1]
   print " ", row[2]
   print " ", row[3]

While running from Sikuli I get this error

[error] ImportError ( No module named psycopg2 )"

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-09-07
Last reply:
2018-09-07
RaiMan (raimund-hocke) said : #1

The interpreter for Python in SikuliX is the Java based Jython.

Usually Python modules depending on C-based libraries cannot be used with Jython and lead to an import error.

Only modules written in Python only with language level 2.7 normally work out of the box.

On the other hand, available Java libraries can be used in any case.

Another problem might be, that you pip-installed the module into the Python environment, which is not automatically available for SikuliX/Jython.

Check/add sys.path accordingly.

Can you help with this problem?

Provide an answer of your own, or ask Hina for more information if necessary.

To post a message you must log in.