Python and SQL Anywhere 17 trouble with "Could not load dbcapi"

1.8k Views Asked by At

I installed SQL Anywhere 17 client. I ran /opt/sqlanywhere17/bin64/sa_config.sh And still have problem with sqlanydb.InterfaceError: ('Could not load dbcapi. Tried:None,dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib', 0)

#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
import ctypes
import sqlanydb
conn = sqlanydb.connect(UserID='XXX', Password='XXX', Host='10.10.10.10', DatabaseName='XXX', ServerName='XXX')
curs = conn.cursor()
curs.close()
conn.close()

Log:

Traceback (most recent call last):
  File "./systest.py", line 6, in <module>
    conn = sqlanydb.connect(UserID='XXX', Password='XXX', Host='10.10.10.10', DatabaseName='XXX', ServerName='XXX')
  File "/usr/local/lib/python3.6/site-packages/sqlanydb.py", line 522, in connect
    return Connection(args, kwargs)
  File "/usr/local/lib/python3.6/site-packages/sqlanydb.py", line 538, in __init__
    parent = Connection.cls_parent = Root("PYTHON")
  File "/usr/local/lib/python3.6/site-packages/sqlanydb.py", line 464, in __init__
    'libdbcapi_r.dylib')
  File "/usr/local/lib/python3.6/site-packages/sqlanydb.py", line 456, in load_library
    raise InterfaceError("Could not load dbcapi.  Tried: " + ','.join(map(str, names)))
sqlanydb.InterfaceError: ('Could not load dbcapi.  Tried: None,dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib', 0)

Thanks for your help in advance

1

There are 1 best solutions below

0
On

I faced the same issue and took me 2 days to solve it.

Here is the solution, your solution is in point 2.

  1. If running on Linux or one of the Unix platforms, you'll need to set up your environment before launching Python. So, download the sql anywhere12 / 17 and install. ( You have done this)

  2. open the terminal and run sa_config{.sh|.csh} script so your Python application can locate the required libraries (including libdbcapi12.dll). Make sure that you run sa_config.sh file and app.py in same terminal otherwise you will face the same issue.

Example, I have created the bash file which run first.

. /opt/sqlanywhere17/bin32/sa_config.sh
python app.py

source : Full answer can be found here on sqlanywhere forum