import ibm_db fails on Windows because the Db2 driver DLLs are not found
Your error
ImportError: DLL load failed while importing ibm_db: The specified module could not be found.1 more line it can showFix it fast
Most common cause, 1 of 3An ibm_db release from 3.2.0 to 3.2.8 that never registers the driver folder
Upgrade to a release that carries the fix.
pip install --upgrade ibm_dbShort answer
ImportError: DLL load failed while importing ibm_db means Python could not find the Db2 clidriver DLLs. Since Python 3.8, Windows ignores PATH for extension DLLs. ibm_db 3.2.0 to 3.2.8 never registered the folder; 3.2.9 and 3.3.0 add an ibm_db_dll.pth hook. Upgrade, check the .pth file exists, and fix or unset IBM_DB_HOME.
Which cause do you have?
Print three facts in one go: the installed ibm_db version, the IBM_DB_HOME value, and whether the startup hook file sits in site-packages. An old version points to cause 1, False to cause 2, a set IBM_DB_HOME to cause 3.
python -c "import os, sysconfig, importlib.metadata as m; print(m.version('ibm_db'), os.environ.get('IBM_DB_HOME'), os.path.isfile(os.path.join(sysconfig.get_path('purelib'), 'ibm_db_dll.pth')))"Then find the line you see in this list and open its fix:
- 1An ibm_db release from 3.2.0 to 3.2.8 that never registers the driver folder
The version printed is 3.2.x below 3.2.9, and the same script worked with 3.1.4 or on Linux - 2The ibm_db_dll.pth hook is missing or Python never runs it
ibm_db is 3.2.9 or newer but the hook check prints False, or Python is started with the -S option - 3IBM_DB_HOME sends the hook to the wrong driver folder
The first command prints a path for IBM_DB_HOME, often one ending in \bin or one left over from an old Db2 client
What does the error look like?
ImportError: DLL load failed while importing ibm_db: The specified module could not be found.OSError: [WinError 87] The parameter is incorrect: 'path to clidriver installation until bin'
Cause 1 of 3
An ibm_db release from 3.2.0 to 3.2.8 that never registers the driver folder
You seeThe version printed is 3.2.x below 3.2.9, and the same script worked with 3.1.4 or on Linux
Check
ImportError: DLL load failed while importing ibm_db appears on these releases because the bundled clidriver\bin folder is never added to the DLL search path. Python 3.8 stopped using PATH to resolve DLLs that an extension module depends on, so having the folder on PATH changes nothing.
pip show ibm_dbFix
Upgrade to a release that carries the fix. Version 3.2.9 added a startup hook that calls os.add_dll_directory() for the clidriver bin folder, and 3.3.0 keeps it.
pip install --upgrade ibm_dbVerify
A new Python process imports both modules without the ImportError.
python -c "import ibm_db, ibm_db_dbi; print('ibm_db loaded')"Confirmed by github.com
Cause 2 of 3
The ibm_db_dll.pth hook is missing or Python never runs it
You seeibm_db is 3.2.9 or newer but the hook check prints False, or Python is started with the -S option
Check
On current releases, the DLL error means the hook did not register clidriver\bin. Import lines in a .pth file are run by Python's site module at start-up, and the -S option switches that module off. A partial install, or a launcher that passes -S, therefore reaches the import with no DLL folder added.
python -c "import os, site, sysconfig; paths=[os.path.join(site.getusersitepackages(),'clidriver','bin'), os.path.join(sysconfig.get_path('purelib'),'clidriver','bin')]; print(next((p for p in paths if os.path.isdir(p)), 'clidriver not found - reinstall ibm_db'))"Fix
Reinstall the package so pip writes the hook again. Where the hook cannot run, register the folder yourself before the import, using the full path that ends in clidriver\bin. Windows accepts only an absolute folder here, so pasting the README's placeholder text literally ends in WinError 87.
pip uninstall -y ibm_db
pip install ibm_db
# fallback inside your script, before the import
import os
os.add_dll_directory(r"C:\venvs\app\Lib\site-packages\clidriver\bin")
import ibm_dbVerify
The hook check prints True after the reinstall, or the script with the explicit path imports ibm_db cleanly.
python -c "import os, sysconfig; print(os.path.isfile(os.path.join(sysconfig.get_path('purelib'), 'ibm_db_dll.pth')))"Confirmed by raw.githubusercontent.com
Cause 3 of 3
IBM_DB_HOME sends the hook to the wrong driver folder
You seeThe first command prints a path for IBM_DB_HOME, often one ending in \bin or one left over from an old Db2 client
Check
When IBM_DB_HOME is set, the hook registers %IBM_DB_HOME%\bin and ignores the clidriver that came inside the wheel. A value that already ends in bin, a deleted folder, or a different client install leaves the import with no matching DLLs. The README also warns that the prebuilt wheel is not meant to run against an external clidriver.
echo %IBM_DB_HOME%
dir "%IBM_DB_HOME%\bin"Fix
If you do not need a separate Db2 client, clear the variable so the bundled driver is used. If you do, point it at the install root (the folder above bin) and build ibm_db from source so it compiles against that client.
set IBM_DB_HOME=
python -c "import ibm_db"
rem only when an external client is required
set IBM_DB_HOME=C:\IBM\clidriver
pip install ibm_db --no-binary :all: --no-cache-dirVerify
The import works in a fresh terminal where IBM_DB_HOME is either empty or names a folder whose bin directory exists.
python -c "import os, ibm_db; print(os.environ.get('IBM_DB_HOME'))"Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Pin ibm_db at 3.2.9 or later in requirements.txt so a fresh Windows machine gets the start-up hook.
- Keep IBM_DB_HOME out of machine-wide environment settings unless a project really builds against an external Db2 client.
- If a launcher or service wrapper starts Python with -S, call os.add_dll_directory() with the clidriver\bin path before any import of ibm_db.
- Before moving a project to Python 3.18, confirm the ibm_db release you pin no longer relies on an import line in a .pth file, since 3.18 ignores those lines.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.