MSLNZ / msl-loadlib

Load a shared library (and access a 32-bit library from 64-bit Python)
MIT License
75 stars 17 forks source link

Cannot start the 32-bit server. #30

Closed louim-lbs closed 2 years ago

louim-lbs commented 2 years ago

Hi, I'm writting a project using msl to load a 32-bits librairy in my 64-bits python environment, but I still have this error (see below). Do you have any idea why I get this error? I tried to re-freeze the 32-bits server without succes.

Error

  File "g:/Projets/Process_Integration/smaract/connexion_smar_client64.py", line 14, in <module>
    smaract = smaract_class_client64()
  File "g:/Projets/Process_Integration/smaract/connexion_smar_client64.py", line 6, in __init__
    super(smaract_class_client64, self).__init__(module32='connexion_smar_server32.py', timeout=30)
  File "C:\Users\lmleb\AppData\Local\Programs\Python\Python37\lib\site-packages\msl\loadlib\client64.py", line 199, in __init__
    utils.wait_for_server(host, port, timeout)
  File "C:\Users\lmleb\AppData\Local\Programs\Python\Python37\lib\site-packages\msl\loadlib\utils.py", line 283, in wait_for_server
    'Timeout after {:.1f} seconds. Could not connect to {}:{}'.format(timeout, host, port)
msl.loadlib.exceptions.ConnectionTimeoutError: Timeout after 30.0 seconds. Could not connect to 127.0.0.1:64299
Instantiating the 32-bit server raised the following exception:
  PyInstallerImportError: Failed to load dynlib/dll 'g:\\Projets\\Process_Integration\\smar\\lib\\Control.dll'. Most likely this dynlib/dll was not found when the application was frozen.
Cannot start the 32-bit server.

Background files

Here are my clien64.py and server64.py files:

from msl.loadlib import Client64

class smar_class_client64(Client64):
    def __init__(self) -> None:
        super(smar_class_client64, self).__init__(module32='file_server32.py')

    def getpos(self): # Method doing things...
        return self.request32('getpos')

if __name__ == "__main__":
    smaract = smar_class_client64()
    print(smar.getpos())
from msl.loadlib import Server32

class smar_class_server32(Server32):
    def __init__(self, host, port) -> None:
        super(smar_class_server32, self).__init__('lib\\Control.dll', 'cdll', host, port)

    def getpos(self):
        return 0

Environnment

jborbely commented 2 years ago

It looks like Control.dll depends on other DLLs, which cannot be found.

See this tip for ways to find out where the dependencies are located.

For example, suppose the dependencies of Control.dll are located in C:\Program Files\Company\lib then you would modify your Client64 subclass to be

class smar_class_client64(Client64):
    def __init__(self) -> None:
        super(smar_class_client64, self).__init__(module32='file_server32.py', append_environ_path="C:\\Program Files\\Company\\lib")

Also see here for more details about the append_environ_path keyword argument.

louim-lbs commented 2 years ago

I was supposing something like that, but I didn't know enough to find it by myself.

Thanks a lot for your answer, it works like a charm!