Overcome ibm_db import error (image not found) on MacOS
If you’ve faced the error while importing ibm_db on MacOS:
import ibm_db
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ImportError: dlopen(/opt/anaconda3/lib/python3.7/site-packages/ibm_db.cpython-37m-darwin.so, 2): Library not loaded: libdb2.dylib
Referenced from: /opt/anaconda3/lib/python3.7/site-packages/ibm_db.cpython-37m-darwin.so
Reason: image not found
Heres how to fix it
Step 1:
Open terminal and navigate to “site-packages”:
1 . “cd /opt/anaconda3/lib/python3.7/site-packages”
(edit this to add your own path)
2. “ls”
Look for the ibm_db.so image might be something like this — ibm_db.cpython-37m-darwin.so
Step 2:
Run the following command in terminal inside site-packages:
install_name_tool -change libdb2.dylib /opt/anaconda3/lib/python3.7/site-packages/clidriver/lib/libdb2.dylib ibm_db.cpython-37m-darwin.so
Step 3:
Run the following command in terminal inside site-packages:
ln -s clidriver/lib/libdb2.dylib libdb2.dylib
Step 4:
Restart your terminal and pycharm (Python IDE) and try to “import ibm_db”, should’ve solved the problem.