cancel
Showing results for 
Search instead for 
Did you mean: 

Could not load dbcapi

Former Member
11,406

Hi,

I am using Raspberry PI 3 Model B and have installed SQL Anywhere 17 on it. I am following SCN blogs which showed how to install SQL Anywhere and also connect to it via a Python program.

http://scn.sap.com/community/sql-anywhere/blog/2014/08/11/sql-anywhere-available-for-linux-on-arm

When I execute my python program, I get an error "Could not load dbcapi".

After installing SQL Anywhere, I used the below commands to set the PATH and create a new DB.

source "/home/pi/MySql/bin32/sa_config.sh"
dbsrv17 –v (returns 17.0.0.1063)
dbinit mysqlaDB.db -dba murali,sql123
dbsrv17 -ud mysqlaDB.db

I installed PIP and sqlanydb libraries using below commands

sudo apt-get install python-pip  
sudo pip install sqlanydb

I copied the sample code to test the python script. I already have pythoin 2.7.9 installed on my Raspberry PI.

import sqlanydb  
conn = sqlanydb.connect(uid=’murali’, pwd='sql123', eng='mysqlaDB', dbn='mysqlaDB' )  
curs = conn.cursor()  
curs.execute("select 'Hello, world!'")  
print "SQL Anywhere says: %s" % curs.fetchone()  
curs.close()  
conn.close()

Below are some information on my Path settings and System OS info.

pi@raspberrypi:~/Sample Code $ env | grep PATH
LD_LIBRARY_PATH=/home/pi/MySql/lib32:
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0    PATH=/home/pi/MySql/bin32:/home/pi/MySql/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

NODE_PATH=/home/pi/MySql/node:

pi@raspberrypi:~/Sample Code $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL=http://www.raspbian.org/RaspbianBugs

However, I was able to use the terminal to connect to the newly created DB using the following commands.

dbspawn -f dbsrv17 -n mysqlaDB -o server.out mysqlaDB.db
dbisqlc

I started the demo DB and tried to use python script to connect to it. It gave me the same error message.

Below is the complete error message.

pi@raspberrypi:~/Sample Code $ sudo python MySQL01.py
Traceback (most recent call last):
  File "MySQL01.py", line 2, in <module>
    conn = sqlanydb.connect(uid='dba', pwd='sql', eng='demo', dbn='demo' )
  File "/usr/local/lib/python2.7/dist-packages/sqlanydb.py", line 522, in connect
    return Connection(args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sqlanydb.py", line 538, in __init__
    parent = Connection.cls_parent = Root("PYTHON")
  File "/usr/local/lib/python2.7/dist-packages/sqlanydb.py", line 464, in __init__
    'libdbcapi_r.dylib')
  File "/usr/local/lib/python2.7/dist-packages/sqlanydb.py", line 456, in load_library
    raise InterfaceError("Could not load dbcapi.  Tried: " + ','.join(names))
TypeError: sequence item 0: expected string, NoneType found

Thanks, Murali

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Ah, yes! SUDO does not export the LD_LIBRARY_PATH environ or other environs unless included on the cmdline .....

You might be able to run it as sudo LD_LIBRARY_PATH=home/pi/MySql/lib32 python MySQL01.py or possibly sudo LD_LIBRARY_PATH=${LD_LIBRARY_PATH} python MySQL01.py

You can break SUDO security model http://serverfault.com/questions/371630/how-to-configure-sudoers-to-always-keep-ld-library-path-envr... but that wouled be unadviseable.

Former Member
0 Kudos

Thanks Nick. I will test it out. Cheers.

Answers (2)

Answers (2)

Former Member

The fact that you are getting this error tends to confirm the Python 'driver' is installed, set up correctly, and is loading correctly.

The next thing to verify is if your installation has the library libdbcapi_r.so installed. And, if it does, verify the location of that is set in your LD_LIBRARY_PATH; this is usually set up for you when you run the sa_config.sh or sa_config.csh which is a required step.

Former Member
0 Kudos

Thanks Nick.

I can verify the existence of the file libdbcapi_r.so inside the lib32 folder. I sourced the file sa_config.sh. Hence below is my path which has the LD_LIBRARY_PATH set to the lib32 folder

pi@raspberrypi:~/Sample Code $ env | grep PATH
LD_LIBRARY_PATH=/home/pi/MySql/lib32:
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
PATH=/home/pi/MySql/bin32:/home/pi/MySql/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
NODE_PATH=/home/pi/MySql/node:
Former Member
0 Kudos

I found the problem. I was running the python program using SUDO command in the front. It seemed to have a problem. If I type in the command "python MySQL01.py" it works fine. I generally use sudo command when my python program access GPIO pins in my raspberry pi.

Thanks, Murali

Former Member
0 Kudos

Hi Guys, I have something similar to this issue

If I run a program inside a virtualenv, everything works fine. Now, I want to debug my code with Paycharm(with pydev debugger)

and got this error -> InterfaceError: (u'Could not load dbcapi. Tried: None,dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib', 0)

after seeing the code of sqlanydb

I found this variable SQLANY_API_DLL and set to /opt/sqlanywhere17/lib64/libdbcapi_r.so

I got this error now -> InterfaceError: ('Failed to initalize dbcapi context, dbcapi version 2 required. Perhaps you are missing some sqlanywhere libaries?', 0)

Any help/ideas?