INTO-CPS-Association / pyfmu

https://into-cps-application.readthedocs.io/en/latest/submodules/pyfmu/docs/index.html
7 stars 2 forks source link

Python 3.8 changes to DLL import on Windows #18

Open clegaard opened 4 years ago

clegaard commented 4 years ago

In Python 3.8 the approach of loading dll's on Windows have been changed with the intention of making it more secure. This means that dll's in the path are no longer automatically included.

https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew

DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution. If your application relies on these mechanisms, you should check for add_dll_directory() and if it exists, use it to add your DLLs directory while loading your library. Note that Windows 7 users will need to ensure that Windows Update KB2533623 has been installed (this is also verified by the installer).

FMPy uses the cdll library to load dlls:

cdll.LoadLibrary('pathto/myfmu.dll') 

Currently, FMPy is being used for testing the exported FMUs. Using Python 3.8 this gives a slightly misleading error:

FileNotFoundError: Could not find module '...\libpyfmu.dll'. Try using the full path with constructor syntax.

image

With the current build recipe for the dll, it depends on the standard runtime libraries. One solution would be to link these statically.