pysodium icon indicating copy to clipboard operation
pysodium copied to clipboard

cant find libsodium.dll on windows

Open hcombination opened this issue 9 years ago • 6 comments

Hi I was having some trouble using your wrapper on windows. I installed the sodium dll in multiple places but ctypes.cdll.LoadLibrary would always return None. I saw a couple of other people having this problem on windows as well. I added the following few lines to the top of your file to search the system path. Thanks

import ctypes
import ctypes.util
import sys
import os
import platform

if platform.system() == 'Windows':
    if platform.machine() == 'AMD64':
        sodium_dll = 'libsodium-64.dll'
    else:
        sodium_dll = 'libsodium.dll'
    def find_libsodium():
        for path in sys.path:
            filename = os.path.join(path, sodium_dll)
            if os.path.isfile(filename):
                return filename
    sodium_path = find_libsodium()
    if not sodium_path:
        raise ValueError('Unable to find libsodium')
    sodium = ctypes.cdll.LoadLibrary(sodium_path)
else:
    sodium = ctypes.cdll.LoadLibrary(ctypes.util.find_library('sodium') or ctypes.util.find_library('libsodium'))

hcombination avatar Apr 01 '17 23:04 hcombination

i think it would be worthwhile to find out why this dll is not found on your system, even as you say you put it into various places. as far as i understand loadlibrary should load the libraries from where your system normally stores them. if loadlibrary cannot find the library then it's probably in the wrong place. i have little experience with windows, but i seem to remember your libraries need to be on the path, have you tried putting the lib in system32 i think that should be by default on the path. otherwise i read by googling that setx path also alters the path system-wise. but i'm really guessing here i have no idea about windows.

stef avatar Apr 02 '17 00:04 stef

i'm not sure sys.path is the right path to check, sys.path is for python modules, libsodium is not a python module. is it possible that it would be enough to pass 'libsodium-64' to ctypes.util.find_library? and have the library in any of the directories where windows is looking for dlls normally?

stef avatar Jan 14 '18 11:01 stef

If windows does have something similar to $LD_LIBRARY_PATH it might make sense to set that instead correctly.

stef avatar Jan 14 '18 11:01 stef

Would it be possible to parameterize the import so that the user of the library could specify the path to where the DLL is? I'm not immediately sure how to do that given that python lacks parametrized imports and pysodium imports the lib automatically without requiring something like an init() call.

robehickman avatar Jan 22 '18 21:01 robehickman

Could you modify this package so that it includes libsodium? https://github.com/pyca/pynacl/ works out of the box on any platform but they lack many of the functions (as does this one, although different ones, go figure - but at least this one is being developed while pynacl hasn't released since May 2020). Certainly you can take from their Github whatever is needed to make it work without installing DLLs by hand?

covert-encryption avatar Nov 21 '21 17:11 covert-encryption

sorry i have no access to windows hosts.

stef avatar Nov 21 '21 18:11 stef