jaseg / python-mpv

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

Installing on Windows with Python 3.5 #18

Closed ZachaRuba closed 7 years ago

ZachaRuba commented 7 years ago

Hello! Running windows 10 with python 3.5.2

To install I used: python -m pip install https://github.com/jaseg/python-mpv/zipball/master

import mpv gives the error:

Traceback:
import mpv
backend = CDLL(ctypes.util.find_library('mpv-1.dll'))
self._handle = _dlopen(self._name, mode)

TypeError: bad argument type for built-in operation

Any suggestions?

Frechdachs commented 7 years ago

It can't find the libmpv library, so ctypes.util.find_library('mpv-1.dll') returns None. CDLL(None) throws the above exception.

Encountered a similar error recently, apparently find_library does not look in the script's location when searching for the library on Windows. Which is unfortunate because on Windows librarys usually get packaged with the application.

Try to replace

backend = CDLL(ctypes.util.find_library('mpv-1.dll'))

with

backend = CDLL('mpv-1.dll')

and it should work.

EDIT: In case you don't have a mpv-1.dll yet, you can download one here. (It's included in the Dev-package.)

ZachaRuba commented 7 years ago

Hello Frechdachs, Thank you for the response! I didn't have the mpv-1.dll file so I just downloaded it.

1) Changed to backend = CDLL('mpv-1.dll')

2) Moved mpv-1.dll into the lib/site-packages folder with mpv.py

Different error; still seems that it can't find the file:

OSError: [WinError 126] The specified module could not be found

Since the find_library does not look in the script's location, I imagine mpv-1.dll has to be moved somewhere else.

Frechdachs commented 7 years ago

If you are using backend = CDLL('mpv-1.dll') then python will look for the library in your system search path and the path of YOUR script. (It will not look in the path of mpv.py)

If you are using backend = CDLL(ctypes.util.find_library('mpv-1.dll')) then python will only look in the system search path.

So just put it in a directory that's in your Path variable and it should work either way.

jaseg commented 7 years ago

@Frechdachs Thank you for the clarification!

I added find_library after #10, but this looks like not using it might actually be a better idea on windows.

ZachaRuba commented 7 years ago

@Frechdachs Thank you! Moved the 32 version mpv-1.dll into the same directory as my script testscript.py that included import mvp-1.dll. Working now. edit: Just tested it with backend = CDLL(ctypes.util.find_library('mpv-1.dll')) and it still works.

To Recap for those who want to install this using python 3.5 on windows 10;

  1. python -m pip install https://github.com/jaseg/python-mpv/zipball/master This will download and install the mpv library
  2. Go to mpv.py in your library. Mine was under; c://Users/User_Name/AppData/Local/Programs/Python/Python35-32/Lib/site-packages
  3. Ensure that backend = CDLL('mpv-1.dll') in the following statement (found at the top of mpv.py)

if os.name == 'nt': backend = CDLL('mpv-1.dll') fs_enc = 'utf-8' else:

  1. Go here download the latest dev package.
  2. From the dev pkg, copy the mpv-1.dll file (try 32 version first) and place it in the same directory as your script that is importing the mpv library

*Side note: if you don't want to have to include the mpv-1.dll file everytime in the same directory as your script then place the mpv-1.dll file under your system search path

Frechdachs commented 7 years ago

edit: Just tested it with backend = CDLL(ctypes.util.find_library('mpv-1.dll')) and it still works.

Odd, I tried it on a Windows 8.1 VM and it only found libmpv if I put it in the system search path.

(try 32 version first)

Well, you have to use 32 bit if your python installation is 32 bit and 64 bit if your python installation is 64 bit.

Frechdachs commented 7 years ago

I added find_library after #10, but this looks like not using it might actually be a better idea on windows.

I don't see an advantage of using find_library on Windows, since apparently you have to specify the full filename anyway.

Frechdachs commented 7 years ago

@jaseg: Oh, and on Linux you should probably check if find_library returns None and raise a less cryptic exception.

jaseg commented 7 years ago

I pushed a commit that should fix this on both windows and linux. It seems to work for me, but if you are bored feel free to test it. I seem to have some weird problem with the unit tests on my (new) setup right now.

Frechdachs commented 7 years ago

Thank you, that is exactly what I had in mind.