[python-package] Cannot import lightgbm after installation on windows with `uv`, lib_lightgbm.dll not found
Description
Cannot import lightgbm after installing it with uv. I am aware uv might not be supported, but I also tried to install it with pip inside the virtual environment, and get the same error.
The error I get when trying to import the package is the following:
FileNotFoundError Traceback (most recent call last)
Cell In[2], line 9
6
7
----> 9 import lightgbm as lgb
10
11
File c:\Users\project\.venv\Lib\site-packages\lightgbm\__init__.py:11
7 from pathlib import Path
9 # .basic is intentionally loaded as early as possible, to dlopen() lib_lightgbm.{dll,dylib,so}
10 # and its dependencies as early as possible
---> 11 from .basic import Booster, Dataset, Sequence, register_logger
12 from .callback import EarlyStopException, early_stopping, log_evaluation, record_evaluation, reset_parameter
13 from .engine import CVBooster, cv, train
File c:\Users\project\.venv\Lib\site-packages\lightgbm\basic.py:9
2 """Wrapper for C API of LightGBM."""
4 # This import causes lib_lightgbm.{dll,dylib,so} to be loaded.
5 # It's intentionally done here, as early as possible, to avoid issues like
6 # "libgomp.so.1: cannot allocate memory in static TLS block" on aarch64 Linux.
7 #
8 # For details, see the "cannot allocate memory in static TLS block" entry in docs/FAQ.rst.
----> 9 from .libpath import _LIB # isort: skip
11 import abc
12 import ctypes
File c:\Users\project\.venv\Lib\site-packages\lightgbm\libpath.py:49
47 _LIB = Mock(ctypes.CDLL) # type: ignore
48 else:
---> 49 _LIB = ctypes.cdll.LoadLibrary(_find_lib_path()[0])
File ~\AppData\Roaming\uv\python\cpython-3.13.2-windows-x86_64-none\Lib\ctypes\__init__.py:471, in LibraryLoader.LoadLibrary(self, name)
470 def LoadLibrary(self, name):
--> 471 return self._dlltype(name)
File ~\AppData\Roaming\uv\python\cpython-3.13.2-windows-x86_64-none\Lib\ctypes\__init__.py:390, in CDLL.__init__(self, name, mode, handle, use_errno, use_last_error, winmode)
387 self._FuncPtr = _FuncPtr
389 if handle is None:
--> 390 self._handle = _dlopen(self._name, mode)
391 else:
392 self._handle = handle
FileNotFoundError: Could not find module 'c:\Users\project\.venv\Lib\site-packages\lightgbm\bin\lib_lightgbm.dll' (or one of its dependencies). Try using the full path with constructor syntax.
Reproducible example
uv add lightgbm
import lightgbm
Environment info
LightGBM version or commit hash: 4.6.0
Command(s) you used to install LightGBM
uv add lightgbm
# alternatively
python -m pip install lightgbm==4.6.0
Windows 10 Powershell 5.1
Additional Comments
Found related issues: #6079, #5335, #5261, stack overflow question
But I haven't been able to fix this, these issues seem to give solutions for building the library from source.
I think I fixed the problem, sorry for opening the issue. It works now after installing Microsoft C++ Build Tools.
Thanks for using LightGBM and for taking the time to report this.
I'm glad that building from source worked for you, but that really should not be necessary. I'd like to understand why uv didn't choose to install the pre-built wheels we publish for Windows.
lightgbm-4.6.0-py3-none-win_amd64.whl
ref: https://pypi.org/project/lightgbm/#files
What does this Python code print for you?
import platform
import sys
print(platform.platform())
print(platform.win32_ver())
print(sys.version)
Could you share the logs from running python -m pip install lightgbm==4.6.0 and/org uv add lightgbm?
I forgot to mention that the binary lib_lightgbm.dll did exist in the path specified by the error message, but I still got the error. And by installing Microsoft C++ build tools, the error disappeared without having to build the package from source (I think).
What does this Python code print for you?
import platform import sys print(platform.platform()) print(platform.win32_ver()) print(sys.version)
Windows-10-10.0.19045-SP0
('10', '10.0.19045', 'SP0', 'Multiprocessor Free')
3.13.2 (main, Feb 12 2025, 14:49:53) [MSC v.1942 64 bit (AMD64)]
Could you share the logs from running
python -m pip install lightgbm==4.6.0and/orguv add lightgbm?
after running python -m pip install lightgbm==4.6.0, I get:
Collecting lightgbm==4.6.0
Using cached lightgbm-4.6.0-py3-none-win_amd64.whl.metadata (17 kB)
Requirement already satisfied: numpy>=1.17.0 in c:\users\project\.venv\lib\site-packages (from lightgbm==4.6.0) (2.2.6)
Requirement already satisfied: scipy in c:\users\project\.venv\lib\site-packages (from lightgbm==4.6.0) (1.15.3)
Using cached lightgbm-4.6.0-py3-none-win_amd64.whl (1.5 MB)
Installing collected packages: lightgbm
Successfully installed lightgbm-4.6.0
after running uv add -v lightgbm I get:
DEBUG Found project root: C:\Users\project
DEBUG No workspace root found, using project root
DEBUG Acquired lock for C:\Users\project
DEBUG Reading Python requests from version file at C:\Users\project\.python-version
DEBUG Using Python request 3.13 from version file at .python-version
DEBUG Checking for Python environment at .venv
DEBUG The project environment's Python version satisfies the request: Python 3.13
DEBUG Released lock at C:\Users\user\AppData\Local\Temp\uv-c3da7c6a15b50a0d.lock
DEBUG Acquired lock for .venv
DEBUG Using request timeout of 30s
DEBUG Found static pyproject.toml for: project @ file:///C:/Users/project
DEBUG No workspace root found, using project root
DEBUG Ignoring existing lockfile due to mismatched requirements for: project==0.1.0
Requested: {Requirement { name: PackageName("lightgbm"), extras: [], groups: [], marker: true, source: Registry { specifier: VersionSpecifiers([]), index: None, conflict: None }, origin: None }}
Existing: {}
DEBUG Solving with installed Python version: 3.13.2
DEBUG Solving with target Python version: >=3.13
DEBUG Adding direct dependency: project*
DEBUG Adding direct dependency: project:dev*
DEBUG Searching for a compatible version of project @ file:///C:/Users/project ()
DEBUG Adding direct dependency: lightgbm
DEBUG Searching for a compatible version of project @ file:///C:/Users/project ()
DEBUG Adding direct dependency: project:dev==0.1.0
DEBUG Searching for a compatible version of project @ file:///C:/Users/project (==0.1.0)
DEBUG Acquired lock for C:\Users\user\.uv_cache\simple-v16\pypi\lightgbm.lock
DEBUG No cache entry for: https://pypi.org/simple/lightgbm/
DEBUG Released lock at C:\Users\user\.uv_cache\simple-v16\pypi\lightgbm.lock
DEBUG Searching for a compatible version of lightgbm ()
DEBUG Selecting: lightgbm==4.6.0 [compatible] (lightgbm-4.6.0-py3-none-macosx_10_15_x86_64.whl)
DEBUG Acquired lock for C:\Users\user\.uv_cache\wheels-v5\pypi\lightgbm\lightgbm-4.6.0-py3-none-macosx_10_15_x86_64.lock
DEBUG No cache entry for: https://files.pythonhosted.org/packages/f2/75/cffc9962cca296bc5536896b7e65b4a7cdeb8db208e71b9c0133c08f8f7e/lightgbm-4.6.0-py3-none-macosx_10_15_x86_64.whl.metadata
DEBUG Released lock at C:\Users\user\.uv_cache\wheels-v5\pypi\lightgbm\lightgbm-4.6.0-py3-none-macosx_10_15_x86_64.lock
DEBUG Adding transitive dependency for lightgbm==4.6.0: numpy>=1.17.0
DEBUG Adding transitive dependency for lightgbm==4.6.0: scipy*
DEBUG Acquired lock for C:\Users\user\.uv_cache\simple-v16\pypi\numpy.lock
DEBUG Acquired lock for C:\Users\user\.uv_cache\simple-v16\pypi\scipy.lock
DEBUG No cache entry for: https://pypi.org/simple/numpy/
DEBUG No cache entry for: https://pypi.org/simple/scipy/
DEBUG Released lock at C:\Users\user\.uv_cache\simple-v16\pypi\scipy.lock
DEBUG Acquired lock for C:\Users\user\.uv_cache\wheels-v5\pypi\scipy\scipy-1.15.3-cp313-cp313-macosx_10_13_x86_64.lock
DEBUG No cache entry for: https://files.pythonhosted.org/packages/73/18/ec27848c9baae6e0d6573eda6e01a602e5649ee72c27c3a8aad673ebecfd/scipy-1.15.3-cp313-cp313-macosx_10_13_x86_64.whl.metadata
WARN Skipping file for numpy: numpy-1.0.1.dev3460.win32-py2.4.exe
WARN Skipping file for numpy: numpy-1.3.0.win32-py2.5.exe
WARN Skipping file for numpy: numpy-1.5.0.win32-py2.6.exe
WARN Skipping file for numpy: numpy-1.5.1.win32-py2.5-nosse.exe
WARN Skipping file for numpy: numpy-1.5.1.win32-py2.6-nosse.exe
WARN Skipping file for numpy: numpy-1.5.1.win32-py2.7-nosse.exe
WARN Skipping file for numpy: numpy-1.5.1.win32-py3.1-nosse.exe
WARN Skipping file for numpy: numpy-1.6.0.win32-py2.5.exe
WARN Skipping file for numpy: numpy-1.6.0.win32-py2.6.exe
WARN Skipping file for numpy: numpy-1.6.0.win32-py2.7.exe
WARN Skipping file for numpy: numpy-1.6.0.win32-py3.1.exe
WARN Skipping file for numpy: numpy-1.6.0.win32-py3.2.exe
WARN Skipping file for numpy: numpy-1.6.1.win32-py2.5.exe
WARN Skipping file for numpy: numpy-1.6.1.win32-py2.6.exe
WARN Skipping file for numpy: numpy-1.6.1.win32-py2.7.exe
WARN Skipping file for numpy: numpy-1.6.1.win32-py3.1.exe
WARN Skipping file for numpy: numpy-1.6.1.win32-py3.2.exe
WARN Skipping file for numpy: numpy-1.6.2.win32-py2.5.exe
WARN Skipping file for numpy: numpy-1.6.2.win32-py2.6.exe
WARN Skipping file for numpy: numpy-1.6.2.win32-py2.7.exe
WARN Skipping file for numpy: numpy-1.6.2.win32-py3.1.exe
WARN Skipping file for numpy: numpy-1.6.2.win32-py3.2.exe
WARN Skipping file for numpy: numpy-1.7.0.win32-py2.5.exe
WARN Skipping file for numpy: numpy-1.7.0.win32-py2.6.exe
WARN Skipping file for numpy: numpy-1.7.0.win32-py2.7.exe
WARN Skipping file for numpy: numpy-1.7.0.win32-py3.1.exe
WARN Skipping file for numpy: numpy-1.7.0.win32-py3.2.exe
WARN Skipping file for numpy: numpy-1.7.0.win32-py3.3.exe
WARN Skipping file for numpy: numpy-1.7.1.win32-py2.5.exe
WARN Skipping file for numpy: numpy-1.7.1.win32-py2.6.exe
WARN Skipping file for numpy: numpy-1.7.1.win32-py2.7.exe
WARN Skipping file for numpy: numpy-1.7.1.win32-py3.1.exe
WARN Skipping file for numpy: numpy-1.7.1.win32-py3.2.exe
WARN Skipping file for numpy: numpy-1.7.1.win32-py3.3.exe
DEBUG Released lock at C:\Users\user\.uv_cache\simple-v16\pypi\numpy.lock
DEBUG Searching for a compatible version of numpy (>=1.17.0)
DEBUG Selecting: numpy==2.3.0 [compatible] (numpy-2.3.0-cp313-cp313-macosx_10_13_x86_64.whl)
DEBUG Acquired lock for C:\Users\user\.uv_cache\wheels-v5\pypi\numpy\numpy-2.3.0-cp313-cp313-macosx_10_13_x86_64.lock
DEBUG No cache entry for: https://files.pythonhosted.org/packages/73/fc/1d67f751fd4dbafc5780244fe699bc4084268bad44b7c5deb0492473127b/numpy-2.3.0-cp313-cp313-macosx_10_13_x86_64.whl.metadata
DEBUG Released lock at C:\Users\user\.uv_cache\wheels-v5\pypi\scipy\scipy-1.15.3-cp313-cp313-macosx_10_13_x86_64.lock
DEBUG Released lock at C:\Users\user\.uv_cache\wheels-v5\pypi\numpy\numpy-2.3.0-cp313-cp313-macosx_10_13_x86_64.lock
DEBUG Searching for a compatible version of scipy ()
DEBUG Selecting: scipy==1.15.3 [compatible] (scipy-1.15.3-cp313-cp313-macosx_10_13_x86_64.whl)
DEBUG Adding transitive dependency for scipy==1.15.3: numpy>=1.23.5, <2.5
DEBUG Tried 4 versions: project 1, lightgbm 1, numpy 1, scipy 1
DEBUG all marker environments resolution took 0.431s
Resolved 4 packages in 443ms
DEBUG Using request timeout of 30s
DEBUG Found static pyproject.toml for: project @ file:///C:/Users/project
DEBUG No workspace root found, using project root
DEBUG Ignoring existing lockfile due to mismatched requirements for: project==0.1.0
Requested: {Requirement { name: PackageName("lightgbm"), extras: [], groups: [], marker: true, source: Registry { specifier: VersionSpecifiers([VersionSpecifier { operator: GreaterThanEqual, version: "4.6.0" }]),
index: None, conflict: None }, origin: None }}
Existing: {Requirement { name: PackageName("lightgbm"), extras: [], groups: [], marker: true, source: Registry { specifier: VersionSpecifiers([]), index: None, conflict: None }, origin: None }}
DEBUG Solving with installed Python version: 3.13.2
DEBUG Solving with target Python version: >=3.13
DEBUG Adding direct dependency: project
DEBUG Adding direct dependency: project:dev*
DEBUG Searching for a compatible version of project @ file:///C:/Users/project ()
DEBUG Adding direct dependency: lightgbm>=4.6.0
DEBUG Searching for a compatible version of project @ file:///C:/Users/project ()
DEBUG Adding direct dependency: project:dev==0.1.0
DEBUG Searching for a compatible version of project @ file:///C:/Users/project (==0.1.0)
DEBUG Searching for a compatible version of lightgbm (>=4.6.0)
DEBUG Selecting: lightgbm==4.6.0 [preference] (lightgbm-4.6.0-py3-none-macosx_10_15_x86_64.whl)
DEBUG Adding transitive dependency for lightgbm==4.6.0: numpy>=1.17.0
DEBUG Adding transitive dependency for lightgbm==4.6.0: scipy*
DEBUG Searching for a compatible version of numpy (>=1.17.0)
DEBUG Selecting: numpy==2.3.0 [preference] (numpy-2.3.0-cp313-cp313-macosx_10_13_x86_64.whl)
DEBUG Searching for a compatible version of scipy (*)
DEBUG Selecting: scipy==1.15.3 [preference] (scipy-1.15.3-cp313-cp313-macosx_10_13_x86_64.whl)
DEBUG Adding transitive dependency for scipy==1.15.3: numpy>=1.23.5, <2.5
DEBUG Tried 4 versions: project 1, lightgbm 1, numpy 1, scipy 1
DEBUG all marker environments resolution took 0.001s
DEBUG Using request timeout of 30s
DEBUG Identified uncached distribution: lightgbm==4.6.0
DEBUG Identified uncached distribution: numpy==2.3.0
DEBUG Identified uncached distribution: scipy==1.15.3
DEBUG Acquired lock for C:\Users\user\.uv_cache\wheels-v5\pypi\scipy\scipy-1.15.3-cp313-cp313-win_amd64.lock
DEBUG Acquired lock for C:\Users\user\.uv_cache\wheels-v5\pypi\numpy\numpy-2.3.0-cp313-cp313-win_amd64.lock
DEBUG Acquired lock for C:\Users\user\.uv_cache\wheels-v5\pypi\lightgbm\lightgbm-4.6.0-py3-none-win_amd64.lock
DEBUG No cache entry for: https://files.pythonhosted.org/packages/5e/23/f8b28ca248bb629b9e08f877dd2965d1994e1674a03d67cd10c5246da248/lightgbm-4.6.0-py3-none-win_amd64.whl
DEBUG No cache entry for: https://files.pythonhosted.org/packages/08/60/61d60cf0dfc0bf15381eaef46366ebc0c1a787856d1db0c80b006092af84/numpy-2.3.0-cp313-cp313-win_amd64.whl
DEBUG No cache entry for: https://files.pythonhosted.org/packages/87/2e/892ad2862ba54f084ffe8cc4a22667eaf9c2bcec6d2bff1d15713c6c0703/scipy-1.15.3-cp313-cp313-win_amd64.whl
Downloading lightgbm (1.4MiB)
Downloading scipy (39.1MiB)
Downloading numpy (12.1MiB)
Downloading lightgbm
DEBUG Released lock at C:\Users\user\.uv_cache\wheels-v5\pypi\lightgbm\lightgbm-4.6.0-py3-none-win_amd64.lock
Downloading numpy
DEBUG Released lock at C:\Users\user\.uv_cache\wheels-v5\pypi\numpy\numpy-2.3.0-cp313-cp313-win_amd64.lock
Downloading scipy
DEBUG Released lock at C:\Users\user\.uv_cache\wheels-v5\pypi\scipy\scipy-1.15.3-cp313-cp313-win_amd64.lock
Prepared 3 packages in 3.90s
Installed 3 packages in 827ms
- lightgbm==4.6.0
- numpy==2.3.0
- scipy==1.15.3
DEBUG Released lock at
C:\Users\project\.venv\.lock
I forgot to mention that the binary lib_lightgbm.dll did exist in the path specified by the error message, but I still got the error. And by installing Microsoft C++ build tools, the error disappeared
Oh that is VERY interesting!
From the logs you shared, it does look like you got a wheel as expected and nothing was built from source.
Given these two things, now I think it's more like "some DLL required by lib_lightgbm.dll wasn't present on your system, and installing the Microsoft C++ build tools provided it".
Since you've now installed those tools, you should have dumpbin installed (docs).
Could you try something like this, and share the outputs here?
dumpbin /dependents "c:\Users\project\.venv\Lib\site-packages\lightgbm\bin\lib_lightgbm.dll"
I found that tool helpful before (https://github.com/microsoft/LightGBM/issues/4464#issuecomment-888803523).
I can also try to reproduce this on a Windows system I have access to, when time permits.
Thank you for helping us to make this better for other Windows users, and very sorry for the inconvenience!
Thanks for your help!
Could you try something like this, and share the outputs here?
dumpbin /dependents "c:\Users\project.venv\Lib\site-packages\lightgbm\bin\lib_lightgbm.dll"
Microsoft (R) COFF/PE Dumper Version 14.44.35209.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file c:\Users\project\.venv\Lib\site-packages\lightgbm\bin\lib_lightgbm.dll
File Type: DLL
Image has the following dependencies:
CFGMGR32.dll
api-ms-win-core-winrt-string-l1-1-0.dll
api-ms-win-core-winrt-l1-1-0.dll
KERNEL32.dll
ole32.dll
ADVAPI32.dll
MSVCP140.dll
VCOMP140.DLL
WS2_32.dll
IPHLPAPI.DLL
VCRUNTIME140.dll
VCRUNTIME140_1.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-locale-l1-1-0.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
Summary
1B000 .data
1C000 .pdata
92000 .rdata
4000 .reloc
1000 .rsrc
315000 .text
same thing here but running out of uv and a graviton ARM processor on AWS. currently getting the following issue:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
Cell In[1], [line 85](vscode-notebook-cell:?execution_count=1&line=85)
83 import xgboost as xgb
84 from xgboost import XGBClassifier
---> [85](vscode-notebook-cell:?execution_count=1&line=85) import lightgbm as lgb
86 from catboost import CatBoostClassifier
88 # ===========================
89 # Ray and Hyperparameter Optimization
90 # ===========================
File ~/.venv/lib/python3.12/site-packages/lightgbm/__init__.py:11
7 from pathlib import Path
9 # .basic is intentionally loaded as early as possible, to dlopen() lib_lightgbm.{dll,dylib,so}
10 # and its dependencies as early as possible
---> [11](https://vscode-remote+ssh-002dremote-002bdeledao-002dmisc.vscode-resource.vscode-cdn.net/home/ubuntu/baseline/~/.venv/lib/python3.12/site-packages/lightgbm/__init__.py:11) from .basic import Booster, Dataset, Sequence, register_logger
12 from .callback import EarlyStopException, early_stopping, log_evaluation, record_evaluation, reset_parameter
13 from .engine import CVBooster, cv, train
File ~/.venv/lib/python3.12/site-packages/lightgbm/basic.py:9
2 """Wrapper for C API of LightGBM."""
4 # This import causes lib_lightgbm.{dll,dylib,so} to be loaded.
5 # It's intentionally done here, as early as possible, to avoid issues like
6 # "libgomp.so.1: cannot allocate memory in static TLS block" on aarch64 Linux.
7 #
8 # For details, see the "cannot allocate memory in static TLS block" entry in docs/FAQ.rst.
----> [9](https://vscode-remote+ssh-002dremote-002bdeledao-002dmisc.vscode-resource.vscode-cdn.net/home/ubuntu/baseline/~/.venv/lib/python3.12/site-packages/lightgbm/basic.py:9) from .libpath import _LIB # isort: skip
11 import abc
12 import ctypes
File ~/.venv/lib/python3.12/site-packages/lightgbm/libpath.py:49
47 _LIB = Mock(ctypes.CDLL) # type: ignore
48 else:
---> [49](https://vscode-remote+ssh-002dremote-002bdeledao-002dmisc.vscode-resource.vscode-cdn.net/home/ubuntu/baseline/~/.venv/lib/python3.12/site-packages/lightgbm/libpath.py:49) _LIB = ctypes.cdll.LoadLibrary(_find_lib_path()[0])
File /usr/lib/python3.12/ctypes/__init__.py:460, in LibraryLoader.LoadLibrary(self, name)
459 def LoadLibrary(self, name):
--> [460](https://vscode-remote+ssh-002dremote-002bdeledao-002dmisc.vscode-resource.vscode-cdn.net/usr/lib/python3.12/ctypes/__init__.py:460) return self._dlltype(name)
File /usr/lib/python3.12/ctypes/__init__.py:379, in CDLL.__init__(self, name, mode, handle, use_errno, use_last_error, winmode)
376 self._FuncPtr = _FuncPtr
378 if handle is None:
--> [379](https://vscode-remote+ssh-002dremote-002bdeledao-002dmisc.vscode-resource.vscode-cdn.net/usr/lib/python3.12/ctypes/__init__.py:379) self._handle = _dlopen(self._name, mode)
380 else:
381 self._handle = handle
OSError: libgomp.so.1: cannot open shared object file: No such file or directory
OSError: libgomp.so.1: cannot open shared object file: No such file or directory
This is not the same issue. You need to install OpenMP to use LightGBM.
On Linux, that is something like:
apt-get install --no-install-recommends -y \
libomp-dev
The specifics vary depending on operating system and on how exactly you install lightgbm (e.g. whether uv chose a wheel or to build from source).
Same issue here on a fresh lightgbm installation via uv running on a Windows Server 2025 instance.
Interestingly enough, if I import xgboost before lightgbm, the import succeeds: import xgboost, lightgbm