Problem with ODBC connection of Ubuntu 14.04 - "Unable to allocate ODBC environment handle!"

User 2032 | 6/7/2015, 7:31:34 PM

Hi there,

I have a problem with connecting to MySQL through ODBC on Ubuntu 14.04LTS.

I've installed UnixODBC and set it up so I can get the following:

import pypyodbc
conn = pypyodbc.connect('Driver=myodbc_mysql;Server=127.0.0.1;port=3306;uid=root;pwd=<PASSWORD>;database=tailor_core')

working.

However when I try a similar thing with graphlab:

query = str(ItemViewAction.objects.all().query)
odbc = gl.connect_odbc(
    'Driver=myodbc_mysql;Server=127.0.0.1;port=3306;uid=root;pwd=<PASSWORD>;database=tailor_core')
sf = gl.SFrame.from_odbc(odbc, query)

I get the following error

RuntimeError: Runtime Exception. Unable to allocate ODBC environment handle!
This is probably because GraphLab Create cannot load libodbc.{so,dylib}.
Have you installed an ODBC driver manager? If you have, set the
directory to the GRAPHLAB_LIBODBC_PREFIX environment variable and
restart GraphLab Create.

I've exported the location of odbc to the .profile:

I found it by:

sudo find / -name '*libodbc.*'
/usr/lib/x86_64-linux-gnu/libodbc.so.1.0.0
/usr/lib/x86_64-linux-gnu/libodbc.so.1

so I added:

export GRAPHLAB_LIBODBC_PREFIX=/usr/lib/x86_64-linux-gnu

to ~/.profile and re-logged to ubuntu.

I also tried:

export GRAPHLAB_LIBODBC_PREFIX=/usr/lib/x86_64-linux-gnu/odbc

without effect.

Trying multiple paths in graphlab.setlibodbcpath didn't work either.

Any suggestions on how to get it to work?

Comments

User 2032 | 6/8/2015, 1:02:56 PM

I managed to solve the problem by creating a symlink

sudo ln -s libodbc.so.1 libodbc.so

in

/usr/lib/x86_64-linux-gnu

and using

export GRAPHLAB_LIBODBC_PREFIX=/usr/lib/x86_64-linux-gnu

in my .profile file.


User 15 | 6/8/2015, 5:17:46 PM

Hi,

Sorry for that inconvenience. I'm glad you figured out the issue. We do indeed only look for a library named "libodbc.so". I'll add some further checks. After setting that symbolic link, I don't think you need to set GRAPHLABLIBODBCPREFIX, as that path is in Ubuntu 14's default system library search path, but it doesn't hurt.

Thanks for bringing this to our attention!

Evan


User 2879 | 1/10/2016, 4:37:19 AM

I'm having the same problem as JohnnyM, however I'm new to symlink or ln in general. Does his solution mean that he didn't have a libodbc.so but did have a libodbc.so.1 so he linked the former filename to the later filename?

I have a libodbc.so file so that means I don't need a symlink right? Are there any other reasons I might get this error? RuntimeError: Runtime Exception. Unable to allocate ODBC environment handle! This is probably because GraphLab Create cannot load libodbc.{so,dylib}. Have you installed an ODBC driver manager? If you have, set the directory to the GRAPHLAB_LIBODBC_PREFIX environment variable and restart GraphLab Create.


User 15 | 1/11/2016, 6:50:59 PM

Hi,

Yes, in his situation this meant he didn't have a file named libodbc.so. Usually the installation procedure of unixODBC sets that symlink automatically, but in his case it didn't. If you have that file, you're correct, you likely don't need the symlink.

The thing to check with this error is whether libodbc.so is able to be found. Every system has paths it searches for .so files by default, and if your libodbc.so is not in one of those folders, then you need to set the GRAPHLABLIBODBCPREFIX environment variable to the directory it is in.

What is the full path of the folder that libodbc.so is in on your system? Also which Linux distribution are you using (I'm assuming Linux because of your libodbc file name)?

Evan


User 5314 | 6/22/2016, 5:47:42 AM

How do I solve this issue on Windows 7? I have pyodbc installed and it works fine in iPython.


User 15 | 6/22/2016, 7:18:32 PM

GraphLab Create's ODBC connector only supports Linux and Mac OS X. If you want to connect to a database on Windows, you could see if your database supports a Python DBAPI2 module, and use our DBAPI2 connector: https://dato.com/products/create/docs/generated/graphlab.SFrame.from_sql.html