ktbarrett / find_libpython

Finds the libpython associated with the current Python environment, wherever it may be hiding.
MIT License
14 stars 7 forks source link

Simplify searching procedure #26

Closed ktbarrett closed 3 years ago

ktbarrett commented 3 years ago

Each operating system and environment tends to do something slightly different, but in general there are general classes of solutions. Using this as a framework, we can change find_libpython to look exactly where it should rather than fuzzy searching.

Linux

Fairly straightforward, the LDLIBRARY always contains the name of the Python shared object. After that, if the library is on the library search path ctypes.util.find_library will find it.

Windows

On Windows sys.dllhandle exists. Which in combination with the kernel function GetModuleFileName can be used to return the path to the executable consistently.

Mac OSX

???

MSYS

Unlike Windows, there is no sys.dllhandle. You can get the name of the library by looking at the DLLLIBRARY sysconfig variable. This returns msys-pythonX.X.dll. LDLIBRARY is used for the import library in this case. However, unlike Linux, ctypes.util.find_library does not work, while loading the library using ctypes.CDLL does... This may be a bug.

MinGW

Similar to Linux in that a ctypes.util.find_library works in general, however, like MSYS, the configuration variable to look at is DLLLIBRARY.

ktbarrett commented 3 years ago

Apparently I'm a big dummy and find_library doesn't always work the way I thought it did...