python-ibmdb: Mac libdb2.dylib image not found

>>> import ibm_db
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/ibm_db.cpython-35m-darwin.so, 2): Library not loaded: libdb2.dylib
  Referenced from: /usr/local/lib/python3.5/site-packages/ibm_db.cpython-35m-darwin.so
  Reason: image not found

This issue can be solved by running

cd /usr/local/lib/python3.5/site-packages
install_name_tool -change libdb2.dylib `pwd`/libdb2.dylib ibm_db.cpython-35m-darwin.so

http://thecourtsofchaos.com/2013/09/16/how-to-copy-and-relink-binaries-on-osx/

However, this needs to be run after pip compiles it. http://stackoverflow.com/questions/1321270/how-to-extend-distutils-with-a-simple-post-install-script

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 23

Commits related to this issue

Most upvoted comments

This is what helped me:

cd /Users/gonzalezma/.pyenv/versions/3.5.2/envs/django-ibm/lib/python3.5/site-packages
install_name_tool -change libdb2.dylib `pwd`/libdb2.dylib ibm_db.cpython-35m-darwin.so
ln -s clidriver/lib/libdb2.dylib libdb2.dylib

Change the path to your site-packages for your virtualenv. The ln -s command was what resolved my issue. The install_name_tool alone did not help me. Hopefully this helps

@theodoretliu not sure to be honest lol I think I noticed that the libdb2.dylib didn’t exist so I created a symlink and then it worked.

I fixed the the Exception by adding: AUTHENTICATION=SERVER.

conn = ibm_db.connect("DATABASE=BIGSQL;HOSTNAME=host;PORT=port;PROTOCOL=TCPIP;UID=gonzalezma;PWD=removed;AUTHENTICATION=SERVER", "", "")

However now in ibm_db_django I get the same error as above. I need to find out how to pass AUTHENTICATION=SERVER to the connection.

I was having the same error and found that the installDSDriver script creates a file at /Applications/dsdriver/db2profile stating the below:

# NAME:     db2profile
#
# FUNCTION: This script sets up a default database environment for
#           Bourne shell or Korn shell users.
#
#           This file is tuned for IBM Data Server Driver Package only.
#
# USAGE:    . db2profile
#           This script can either be invoked directly as above or
#           it can be added to the user's .profile file so that the
#           database environment is established during login.
#

so I just added on my ~/.bash_profile the line below:

source /Applications/dsdriver/db2profile

Open a new terminal window or restart your mac and should work. This file exports all the environment variables needed for the db2cli command to work.

none of the above approaches fixed my issue with libdb2.dylib I am on a Mac and Python 3.6.5 :: Anaconda, Inc.

if you dont want to alter your bash_profile then you can add this

DYLD_LIBRARY_PATH="$VIRTUAL_ENV/lib/python3.6/site-packages/clidriver/lib/icc"
export DYLD_LIBRARY_PATH

to ./venv/bin/activate.

My approach in fixing this was to add this to my bash profile:

export DYLD_LIBRARY_PATH="/anaconda/lib/python2.7/site-packages/clidriver/lib:$DYLD_LIBRARY_PATH"

I did this after identifying where libdb2.dylib was located which I did on my mac by doing the ff steps:

  1. command + space
  2. type `libdb2.dylib
  3. hit enter and see this
/anaconda/lib/python2.7/site-packages/clidriver/lib/libdb2.dylib

Reactivate the bash profile with source ~/.bash_profile and voila, problem solved

using python 2.7.13

@genomics-geek thanks for all your help!

@genomics-geek You are absolutely awesome. This gave me grief for 6 hours+. Yes!