jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
531 stars 67 forks source link

ctypes.util.find_library() Fails to find Windows libmpv-2.dll #258

Closed Axle-Ozz-i-sofT closed 7 months ago

Axle-Ozz-i-sofT commented 1 year ago

Hi I have been attempting to use your mpv.py to test using libmpv and encountered what looks like a long term issue with ctypes ctypes.util.find_library()

I have attempted the original suggestion:

OSError('Cannot find mpv-1.dll or mpv-2.dll in your system %PATH%. One way to deal with this is to ship '
                      'the dll with your script and put the directory your script is in into %PATH% before '
                      '"import mpv": os.environ["PATH"] = os.path.dirname(__file__) + os.pathsep + os.environ["PATH"] '
                      'If mpv-1.dll is located elsewhere, you can add that path to os.environ["PATH"].')

As well as adding the libmpv-2.dll to the current python IDE path, to Windows temporary %PATH%, as well as placing a permanent path to the dll in the system environment paths (via the registry). I have placed the dll in the script directory, in the python /bin dir, in the mpv.py module directory as also in the Windows system directory. ++++

In every instance ctypes.util.find_library() cannot find the dll in any Windows path location. I guess this is a problem with ctypes ctypes.util.find_library() and they even state that it has some issue on Windows.

On Windows, find_library() searches along the system search path, and returns the full pathname, but since there is no predefined naming scheme a call like find_library("c") will fail and return None.

If wrapping a shared library with ctypes, it may be better to determine the shared library name at development time, and hardcode that into the wrapper module instead of using find_library() to locate the library at runtime.

I had this same issue just recently with a binder I created for sqlite2.dll The only solution I had was to hard code the dll path directly into the binder. Not very flexible :(

The only way I can seam to use mpv.py at the moment is to place it in the project script directory (convenience) and modify the module with the static path.

if os.name == 'nt':
    # Note: mpv-2.dll with API version 2 corresponds to mpv v0.35.0. Most things should work with the fallback, too.
    dll = os.path.join(sys.path[0], "libmpv-2.dll")
    #dll = ctypes.util.find_library('mpv-2.dll') or ctypes.util.find_library('mpv-1.dll')

Have you (anyone) found a solution to this?

Windows 10 x64 Python 3,9.6 x64 (Path not set in system environment. Use CMD "py script.py" or "full path\python.exe script.py) Or CMD SET SET PATH=%PATH%;SET PATH=%PATH%;Drive:\full path\ptython script.py or temp path provided by the IDE and python. etc. libmpv V0.35.1 x86-64

Regards Axle

jaseg commented 7 months ago

Ok, there's two things to address here: