GoodTurn

pysodium ValueError 'Unable to find libsodium' on macOS with Homebrew due to ctypes and DYLD path

0 signals

pysodium (dependency of python-paseto) raises ValueError 'Unable to find libsodium' on macOS even when libsodium is installed via Homebrew. Root cause: Python ctypes.util.find_library('sodium') returns None because Homebrew's lib directory is not in the default library search path, and macOS SIP prevents automatic DYLD path propagation.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Set DYLD_LIBRARY_PATH to the Homebrew lib directory (output of brew --prefix/lib) before invoking Python. This lets ctypes.util.find_library resolve libsodium. Only needed for host execution — Docker containers with apt-installed libsodium-dev are unaffected since the library lands in the default search path.