Skip to content

Conversation

simo1427
Copy link

In issue #51 I suggested doing this; it was mentioned in issue #23 as well. On every machine, on which I tried installing the library, I had to edit this line.

In issue #51 I suggested doing this; it was mentioned in issue #23 as well. On every machine, on which I tried installing the library, I had to edit this line.
@simo1427 simo1427 closed this Oct 16, 2020
@simo1427 simo1427 reopened this Oct 16, 2020
@simo1427
Copy link
Author

Closed by mistake

@bgilbert
Copy link
Member

find_library() should generally not be used at runtime. Have you tried adding the OpenSlide bin directory to the beginning of your search path?

@simo1427
Copy link
Author

Yes but to no avail, I even tried doing so in a standalone script with ctypes.cdll.LoadLibrary in it - it still doesn’t work, but find_library continues to find the DLL.

@crisz
Copy link

crisz commented Oct 31, 2020

After hours (if not days) of research, this is the only fix working

@jesper-molin
Copy link

I also have this issue and looked how to fix it, Python changed the default behavior in 3.8 to no longer look in PATH when resolving DLL:s on Windows. In the what's new notes, they recommend using add_dll_directory() to resolve this issue or use an absolute path, but then you need to know where to look.

The only reasonable way to search the PATH is to use find_library, if you want to protect against DLL hijacking, the project needs to deliver the win-DLL to a known location and not depending on it being in the PATH. See e.g. for another project's similar problem: beetbox/pyacoustid#54

So I think this is a good patch.

@bgilbert
Copy link
Member

Okay, yeah, the behavior change in 3.8 seems to explain it. Does the sample code in #115 (comment) work for you?

In the what's new notes, they recommend using add_dll_directory() to resolve this issue or use an absolute path, but then you need to know where to look.

add_dll_directory() seems reasonable. OpenSlide Python assumes that OpenSlide is provided by some external mechanism, which on Windows is almost certainly under the control of the application.

@simo1427
Copy link
Author

I pointed the path to the bin directory of the openslide installation and I can confirm that the quoted code worked.

@alessiamarcolini
Copy link

Hello maintainers, I was wondering when is this PR going to be merged :) thank you

@bgilbert
Copy link
Member

@alessiamarcolini On Python 3.8 and later, applications should use the new os.add_dll_directory() Python function to add the OpenSlide DLL directory to the search path before importing openslide. We'll update the documentation to include example code, but for now, see #115 (comment).

Since this PR bypasses the new Python API, I'll close. Thanks for sending!

@bgilbert bgilbert closed this Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants