-
Notifications
You must be signed in to change notification settings - Fork 42
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
dll issue for python 3.8+ #235
Comments
Linking this very detailed StackOverflow answer for later |
I don't think that answer in StackOverflow is correct anymore. It might have been correct at the time it was written (2014) but the Tom, can you check:
|
From the microsoft docs website, the standard DLL search order for desktop applications is:
The first two aren't included by Python 3.8+, which only searches This leads to the question of where, ideally, should the DLL(s) be? The microscope package path isn't automatically in the |
(I'm going to test |
|
#237 Should be an adequate fix. Feel free to suggest/make any changes if you'd prefer it done differently. |
A quick look and I only have one thought. Is there ever a possibility that kwargs might be populated before you do this? If so then we need to test for this before setting it to an empty dict. |
Is that what you mean, or am I misunderstanding? |
No you are misunderstanding. I am saying what happens if somewhere else in the code someone is passing in parameters via kwargs. This code overwrites the kwargs with no test to see if it already exists. This might be difficult to diagnose, might be sensible to use a different variable name. |
Ah, I see what you mean. I did check upstream of that but I am thinking that maybe a DLL loading function should be put somewhere sensible in microscope to avoid the duplication of code, which would also keep the `kwarg` variable local. I'll fiddle about later or tomorrow
…________________________________
From: Ian Dobbie ***@***.***>
Sent: Tuesday, March 29, 2022 6:24:20 PM
To: python-microscope/microscope ***@***.***>
Cc: Fish, Thomas (DLSLtd,RAL,LSCI) ***@***.***>; Author ***@***.***>
Subject: Re: [python-microscope/microscope] dll issue for python 3.8+ (Issue #235)
No you are misunderstanding. I am saying what happens if somewhere else in the code someone is passing in parameters via kwargs. This code overwrites the kwargs with no test to see if it already exists. This might be difficult to diagnose, might be sensible to use a different variable name.
—
Reply to this email directly, view it on GitHub<#235 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AL6IKWYCGF5623P2Q527U4LVCM4EJANCNFSM5OVV2QPQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
--
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
|
Okay, I've added a new commit that refactors library loading into a general function in _utils.py. Let me know what you think (latest commit is here) |
Thats a good idea, just a quick dllLoad function that can do the correct magic and make it easier to dix if the python, windows etc, changes break the path finding again. |
Since Python 3.8, ctypes uses an altered search path when loading DLLs in Windows which only includes the application directory, the system32 directory, and directories manually specified with add_dll_directory. None of those suit us. The standard search path can be specified with `winmode=0`. This commit adds a new function to loads libraries with `winmode=0` and makes all modules that load shared libraries use it.
I've looked at @thomasmfish fix but it assumes that under Windows one always uses This restores the use of windows default search path and fixes this issue. Closing as fixed. Some thoughts on taking this approach. Python 3.8 uses an altered search path. There appears to be two reasons for it, 1) security (I guess that's because
Which is no good for us. The dll we want to use are in none of those places and we can't expect users to be able to move them there. Why? Because we can't guess where the dlls are, and we can't rely on the users knowing where the dlls and its dependencies are (which means we can't expect them to move them to a specific place either). We can only rely on the installer of the libraries we wrap to install the dlls somewhere and add them to The discussion in Python is in BPO-36085 and is a bit long. There's plenty of discussion but it seems the "only?" use case they're considering is Python packages with dlls on it and not Python packages that wrap libraries that they expect the system to have (which is what we are). |
commit c2b3dc5 Author: Ian Dobbie <[email protected]> Date: Tue Aug 22 12:21:54 2023 -0400 Added the required getValues function to the raspberrypi valueLogger module. commit fa592d6 Author: David Miguel Susano Pinto <[email protected]> Date: Tue Aug 22 13:52:42 2023 +0100 RPiValueLogger: check for availability of MCP9808 and TSYS01 classes. commit bcd3d86 Author: David Miguel Susano Pinto <[email protected]> Date: Tue Aug 22 13:44:11 2023 +0100 PiCamera: use ROI field names instead of tuple index for readability commit 8f631d7 Author: David Miguel Susano Pinto <[email protected]> Date: Tue Aug 22 13:42:07 2023 +0100 maint: black and isort for consistent style. commit 03e6b5c Author: David Miguel Susano Pinto <[email protected]> Date: Tue Aug 22 12:42:09 2023 +0100 Use a standard search path for DLL loading in windows (python-microscope#235) Since Python 3.8, ctypes uses an altered search path when loading DLLs in Windows which only includes the application directory, the system32 directory, and directories manually specified with add_dll_directory. None of those suit us. The standard search path can be specified with `winmode=0`. This commit adds a new function to loads libraries with `winmode=0` and makes all modules that load shared libraries use it. commit 6a4ee44 Author: Ian Dobbie <[email protected]> Date: Mon Aug 21 14:01:48 2023 -0400 Fix picamera roi code to use the ROI named tuples and then just return roi python-microscope#279 commit 76a6364 Author: Ian Dobbie <[email protected]> Date: Mon Jul 24 22:09:11 2023 -0400 Added pulldata option to allow cockpit to pull data from valuelogger devices
https://bugs.python.org/issue43173
This can be fixed with a simple:
with os.add_dll_directory(os.getcwd()):
before any code that imports dlls, or something similar (maybeos.path.dirname(microscope.__file__)
instead ofos.getcwd()
?)The text was updated successfully, but these errors were encountered: