Skip to content

Instantly share code, notes, and snippets.

@chiragjn
Created July 18, 2023 12:02
Show Gist options
  • Save chiragjn/ed864dc86d8b32aac706ba3b9bf033b2 to your computer and use it in GitHub Desktop.
Save chiragjn/ed864dc86d8b32aac706ba3b9bf033b2 to your computer and use it in GitHub Desktop.
Put nvidia libs in site-packages on your LD_LIBRARY_PATH for other cuda compatible libraries to find
import os
import site
import glob
lib_paths = []
for location in site.getsitepackages():
for path in glob.glob(os.path.join(location, "nvidia/**/lib*.so*"), recursive=True):
to_add = os.path.dirname(path)
if to_add not in lib_paths:
lib_paths.append(to_add)
if os.getenv("LD_LIBRARY_PATH"):
lib_paths.extend(os.environ["LD_LIBRARY_PATH"].split(os.pathsep))
ld_library_path_value = os.pathsep.join(lib_paths)
print(f"Setting LD_LIBRARY_PATH to {ld_library_path_value}")
os.environ["LD_LIBRARY_PATH"] = ld_library_path_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment