blond-admin / BLonD

BLonD (Beam Longitudinal Dynamics)
http://blond.web.cern.ch
GNU General Public License v3.0
19 stars 23 forks source link

Windows Python 3.8 dll import fix #188

Closed mvadai closed 3 years ago

mvadai commented 3 years ago

The dll import mechanism has changed in Windows from Python 3.8.

Instead of an external path, the dll-s are imported from the application via a new function in 3.8: https://docs.python.org/3/library/os.html#os.add_dll_directory Explanation: https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew

Furthermore, ctypes.CDLL has to specify a winmode flag how this dll should be imported, also new in 3.8. https://docs.python.org/3/library/ctypes.html#ctypes.CDLL However the default value of winmode is None and not 0 as documented. 0 has to be explicitly specified.

kiliakis commented 3 years ago

Just to complicate things a bit more, we can add another option on the table: with platform.python_version() we can get the python version and compare it with 3.8 instead of looking for the existence of the add_dll_directory() method.

scpalbright commented 3 years ago

Just to complicate things a bit more, we can add another option on the table: with platform.python_version() we can get the python version and compare it with 3.8 instead of looking for the existence of the add_dll_directory() method.

Only down side of that is keep track of version numbers, which would probably be fine, but I think is potentially a little more fragile.

kiliakis commented 3 years ago

Just to complicate things a bit more, we can add another option on the table: with platform.python_version() we can get the python version and compare it with 3.8 instead of looking for the existence of the add_dll_directory() method.

Only down side of that is keep track of version numbers, which would probably be fine, but I think is potentially a little more fragile.

Keep track of what exactly? The check will be something like if platform.python_version() >= 3.8 (adjusted for version comparison) . To me this shows more clearly that this check was put there to support something modified in python-3.8, than checking for the existence of a method which was added in python-3.8.

scpalbright commented 3 years ago

Keep track of what exactly? The check will be something like if platform.python_version() >= 3.8 (adjusted for version comparison) . To me this shows more clearly that this check was put there to support something modified in python-3.8, than checking for the existence of a method which was added in python-3.8.

I'm thinking of the, albeit unlikely, possibility that it gets changed again in a later version.

mvadai commented 3 years ago

I went for checking for the add_dll_directory method, because I wanted to check for the behaviour and not the version that does the behaviour. Furthermore this is the explicitly advised method: https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew