Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant find libsodium.dll on windows #59

Open
hcombination opened this issue Apr 1, 2017 · 6 comments
Open

cant find libsodium.dll on windows #59

hcombination opened this issue Apr 1, 2017 · 6 comments

Comments

@hcombination
Copy link

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'))
@stef
Copy link
Owner

stef commented Apr 2, 2017

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
Copy link
Owner

stef commented Jan 14, 2018

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
Copy link
Owner

stef commented Jan 14, 2018

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

@robehickman
Copy link
Contributor

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.

@covert-encryption
Copy link

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?

@stef
Copy link
Owner

stef commented Nov 21, 2021

sorry i have no access to windows hosts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants