Skip to content
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

python find_library doesn't behave as expected #2357

Open
ktbarrett opened this issue Mar 1, 2021 · 7 comments
Open

python find_library doesn't behave as expected #2357

ktbarrett opened this issue Mar 1, 2021 · 7 comments

Comments

@ktbarrett
Copy link

Describe the issue

Attempting to get the path to the libpython, I try the following:

>>> sysconfig.get_config_var("DLLLIBRARY")
'msys-pythonX.X.dll'
>>> ctypes.util.find_library("msys-pythonX.X.dll")
>>> ctypes.util.find_library("pythonX.X.dll")`
'msys-pythonX.X.dll'
>>> ctypes.CDLL("msys-pythonX.X.dll")
<CDLL 'msys-python3.8.dll', handle 5e6ab0000 at 0x6ffffff16790>

This seems a bit off... find_library doesn't seem to be doing anything useful here.

On Linux, Mac, Windows, and MinGW environments it returns the full path to the library, if found.

Steps to Reproduce the Problem

  1. Run
import sysconfig, ctypes.util
ctypes.util.find_library(sysconfig.get_config_var("DLLLIBRARY"))
  1. Have path to Python object
@ktbarrett
Copy link
Author

Cannot work around this either since I can't seem to access kernel32?

@ktbarrett
Copy link
Author

Patch for find_library is here. It doesn't seem to take LD_LIBRARY_PATH into account? And it only considers investigating import libraries, returning their linked dynamic library instead of a file path. It doesn't seem like it was implemented correctly when compared against the documentation.

@lazka
Copy link
Member

lazka commented Mar 1, 2021

Here is the upstream patch: https://cygwin.com/git-cygwin-packages/?p=git/cygwin-packages/python38.git;a=blob;f=3.7-ctypes-cygwin.patch;h=62e360cb4bced797afe8ea80d1524b4d38892e49;hb=HEAD

I guess the thing is that we have sys.platform == "msys", so we should adjust that patch. Can you try changing that file on your machine to check for "msys" there and see if it helps?

@ktbarrett
Copy link
Author

As installed I see the check is elif sys.platform in ["cygwin", "msys"]: Not sure where that is coming from, it's not upstream. And the observed behavior follows the patch (same as what you posted as well), which is what doesn't seem correct.

@lazka
Copy link
Member

lazka commented Mar 1, 2021

ah, then there is probably another patch on top of that somewhere.

@ktbarrett
Copy link
Author

Should I take this issue upstream? Or should I replace the cygwin patch with something more correct? In the meantime is there an alternative way to get the full path to a library? If I had access to kernel32, I could use GetModuleFileName to get the file path.

@ktbarrett
Copy link
Author

I tried using dladdr to get the filename, with no luck. I don't think there is a way to solve this until the original patch is updated to also search for DLLs. I'll work on that soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants