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

Mac OS X update breaks pymediainfo #24

Closed
mattbodman opened this issue Apr 2, 2016 · 65 comments
Closed

Mac OS X update breaks pymediainfo #24

mattbodman opened this issue Apr 2, 2016 · 65 comments

Comments

@mattbodman
Copy link

Could have been the update to OS X 10.11.4 or an update of Command Line Tools (sorry I'm not sure which caused it). However, using CDLL no longer works.. This error results: OSError: dlopen libmediainfo.so.0, 6 cannot be found, so I guess Apple moved something. This exact happened after the upgrades on two separate Apple machines and the fix below worked for both.

To fix, I rolled back pymediainfo to v 1.4

@sbraz
Copy link
Owner

sbraz commented Apr 2, 2016

Are you using the git version or the 2.0 release?
On 2 Apr 2016 09:14, "Matt Bodman" notifications@github.com wrote:

Could have been the update to OS X 10.11.4 or an update of Command Line
Tools (sorry I'm not sure which caused it). However, using CDLL no longer
works.. This error results: OSError: dlopen libmediainfo.so.0, 6 cannot be
found, so I guess Apple moved something. This exact happened after the
upgrades on two separate Apple machines and the fix below worked for both.

To fix, I rolled back pymediainfo to v 1.4


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#24

@sbraz
Copy link
Owner

sbraz commented Apr 2, 2016

If you use the git version, it should never attempt to load the .so: cb0f6f4#diff-78f1fb93e3c37202e83112bf2277293dR70

@mattbodman
Copy link
Author

Ok thanks. Yes, it was v2.0 that pip installed.

@sbraz
Copy link
Owner

sbraz commented Apr 3, 2016

Can you please try the git version? pip install git+https://github.com/sbraz/pymediainfo.git
I have not made a new release yet as there are still quite a few bugs around.

@mattbodman
Copy link
Author

Still didn't work. Here is the error traceback:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Volumes/Extra/Repos/env/lib/python2.7/site-packages/pymediainfo/__init__.py", line 72, in parse lib = CDLL("libmediainfo.0.dylib") File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__ self._handle = _dlopen(self._name, mode) OSError: dlopen(libmediainfo.0.dylib, 6): image not found

@sbraz
Copy link
Owner

sbraz commented Apr 3, 2016

Is it called something else on your system?

@mattbodman
Copy link
Author

There's this file:

/Applications/MediaInfo.app/Contents/Resources/libmediainfo.dylib

@sbraz
Copy link
Owner

sbraz commented Apr 3, 2016

That's weird, it means the official Python bindings have it wrong…
https://github.com/MediaArea/MediaInfoLib/blob/master/Source/MediaInfoDLL/MediaInfoDLL.py#L34
I don't have a Mac computer but I should be able to get my hands on one at some point. I really need to do it as it seems many people use the package on Mac OS.

@sbraz
Copy link
Owner

sbraz commented Apr 3, 2016

There is a libmediainfo.0.dylib file in http://mediaarea.net/download/binary/libmediainfo0/0.7.84/MediaInfo_DLL_0.7.84_Mac_i386+x86_64.tar.bz2, please make sure this is the version you are using.

@mattbodman
Copy link
Author

Ah ok. I was using, and have always just installed the CLI version because I use MediaInfo outside Python as well. Pymediainfo traditionally worked with the CLI, obviously. Maybe its worth mentioning the DyLib version in your install docs or something? (if you haven't already)

@sbraz
Copy link
Owner

sbraz commented Apr 3, 2016

Since I took over development (version 2.0), the command-line application is no longer used. The changelog mentions it but maybe not clearly enough.
You can still parse XML generated by the CLI version if you want to:

pymediainfo.MediaInfo(subprocess.check_output(["mediainfo", "--output=XML", "-f", "filename.ext"]))

Using the library is just easier and more efficient.
I will try to make the documentation more clear and I'll release a new version as soon as you can confirm that the git version now works on your setup.

@mattbodman
Copy link
Author

Ok, makes sense. I'm actually unsure where to put the DyLib file. Do you know? I tried putting in the directory from where I'm running Python... it seems pymediainfo finds the DyLib file, but results in Python crashing with a segmentation fault. (Python 2.7.8)

@sbraz
Copy link
Owner

sbraz commented Apr 6, 2016

I have little experience with Mac OS, did you manage to make it work? It probably goes to /lib or similar.

@sbraz
Copy link
Owner

sbraz commented Apr 16, 2016

Hi @mattbodman, did you manage to load the dylib properly? Can we close this issue?

@mattbodman
Copy link
Author

Sorry, haven't had a chance to try it. Close it if you like
On 17 Apr 2016 5:09 AM, "Louis Sautier" notifications@github.com wrote:

Hi @mattbodman https://github.com/mattbodman, did you manage to load
the dylib properly? Can we close this issue?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#24 (comment)

@mattbodman
Copy link
Author

I actually ran out of time to figure out where to put the dylib file, so I reverted to Linux. Sorry about that.

@DanielHaitink
Copy link

I have this issue too, maybe useful if the issue could be reopened?

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymediainfo/__init__.py", line 74, in parse
    lib = CDLL("libmediainfo.0.dylib")
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ctypes/__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libmediainfo.0.dylib, 6): image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "downloadSubs.py", line 61, in <module>
    exploreMaps(map)
  File "downloadSubs.py", line 38, in exploreMaps
    if isVideo(currentFile):
  File "downloadSubs.py", line 19, in isVideo
    media_info = MediaInfo.parse(file)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pymediainfo/__init__.py", line 76, in parse
    lib = CDLL("libmediainfo.dylib")
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ctypes/__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libmediainfo.dylib, 6): image not found

@sbraz
Copy link
Owner

sbraz commented Jul 10, 2016

Hi!
Where is the dylib located?

@sbraz sbraz reopened this Jul 10, 2016
@DanielHaitink
Copy link

Hey! The file libmediainfo.dylib is in /Applications/MediaInfo.app/Contents/Resources. I downloaded it from the app store. I believe this is the one you wanted to know the location of?

@sbraz
Copy link
Owner

sbraz commented Jul 11, 2016

I'm no Mac expert but I think that simply overriding LD_LIBRARY_PATH to include the containing folder would fix the issue. Can you try adding this before you load pymediainfo?

os.environ["LD_LIBRARY_PATH"] = os.environ.get("LD_LIBRARY_PATH", "") +  ":/Applications/MediaInfo.app/Contents/Resource"

@DanielHaitink
Copy link

Nope, sorry still doesn't work, the error is the same. I have solved my program without using pymediainfo though.

@sbraz
Copy link
Owner

sbraz commented Jul 11, 2016

What about

os.environ["DYLD_LIBRARY_PATH"] = os.environ.get("DYLD_LIBRARY_PATH", "") +  ":/Applications/MediaInfo.app/Contents/Resource"

@DanielHaitink
Copy link

DanielHaitink commented Jul 11, 2016

Nope sorry, still the same error

Edit: This happens if I run it with python3 if I use python it says Traceback (most recent call last): File "/Users/XXX/documents/test.py", line 1, in <module> from pymediainfo import MediaInfo ImportError: No module named pymediainfo
However it is installed

@OmgImAlexis
Copy link

Are there any updates with this?

@sbraz
Copy link
Owner

sbraz commented Nov 6, 2016

@OmgImAlexis I don't really know, I can't reproduce it myself as I don't have a Mac to test all the time.
Does it work if you point DYLD_LIBRARY_PATH to the right location and export it before running a Python programme?

@OmgImAlexis
Copy link

Yes and also works if we use DYLD_FALLBACK_LIBRARY_PATH.

We also tried editing pymediainfo and adding this before the command to try CDLL. From the looks of it the ENV param needs to be set before Python starts, I wonder if you could get around that by starting it and then forking the process or does Python itself need restarting?

os.environ['DYLD_FALLBACK_LIBRARY_PATH'] = os_folder + ':' + os.environ.get('DYLD_FALLBACK_LIBRARY_PATH', '')

os_folder is the absolute path to our copy of libmediainfo.0.dylib.

@OmgImAlexis
Copy link

@ratoaq2

@sbraz
Copy link
Owner

sbraz commented Nov 6, 2016

Nice, thanks for testing! I'll borrow someone's Mac and perform more tests. Maybe ctypes has a parameter to add more paths from which to load its libraries.

@fralomba
Copy link

It doesn't work for me...any other idea? the error continues being: "OSError: dlopen(libmediainfo.dylib, 6): image not found"

@sbraz
Copy link
Owner

sbraz commented Sep 26, 2017

@fralomba where is your lib located?

@fralomba
Copy link

I have installed it with pip, and tried to follow @GiancarloFusiello 's hint but nothing changed. Same error. The lib is located in usr/local/lib. Do u know how to help me?

@patelsp
Copy link

patelsp commented Sep 27, 2017

@fralomba Here is what I did & works ...

Download & Extract following

  1. https://mediaarea.net/en/MediaInfo/Download/Mac_OS/v0.7.99 (CLI version)
  2. http://mediaarea.net/download/binary/libmediainfo0/0.7.84/MediaInfo_DLL_0.7.84_Mac_i386+x86_64.tar.bz2

Create directory
3) sudo mkdir /usr/local/lib NOTE: Can't use "/usr/lib" is protected by SIP
4) copy extracted libmediainfo.0.dylib into /usr/local/lib
copy same file with name as libmediainfo.dylib

Modify (replace username)
5) /Users/username/Downloads/pymediainfo-2.1.9/pymediainfo/init.py
line 79 change to return CDLL("/usr/local/lib/libmediainfo.0.dylib")
line 81 change to return CDLL("/usr/local/lib/libmediainfo.dylib")

Install (replace username)
6) cd /Users/username/Downloads/pymediainfo-2.1.9/

  • python setup.py build
  • python setup.py install

@sbraz
Copy link
Owner

sbraz commented Sep 27, 2017

@fralomba Just to be sure: you're aware that pip does not install the mediainfo library, right?

@sbraz sbraz closed this as completed in 05ae189 Nov 7, 2017
@sbraz
Copy link
Owner

sbraz commented Nov 7, 2017

There should be no need to move dylib files around. With the latest version, you can simply pass the dylib path to parse's library_file parameter:
05ae189#diff-78f1fb93e3c37202e83112bf2277293dR101

@joyearnaud
Copy link

Hi,
I have OS Big Sur 11.2.2, I have tried out all the solutions in this thread but still getting the error

Traceback (most recent call last):
  File "/Users/xxx/Project/filesort/run.py", line 11, in <module>
    sort_files(PATH, length = LENGTH)
  File "/Users/xxx/Project/filesort/filesort/sort_files.py", line 36, in sort_files
    sort_other(filepath, out_repo)
  File "/Users/xxx/Project/filesort/filesort/sort_files.py", line 167, in sort_other
    if is_video(filepath, out_repo):
  File "/Users/xxx/Project/filesort/filesort/sort_files.py", line 157, in is_video
    media_info = MediaInfo.parse(filepath, library_file="/usr/local/lib/libmediainfo.dylib")
  File "/Users/xxx/Library/Python/3.8/lib/python/site-packages/pymediainfo/__init__.py", line 422, in parse
    lib, handle, lib_version_str, lib_version = cls._get_library(library_file)
  File "/Users/xxx/Library/Python/3.8/lib/python/site-packages/pymediainfo/__init__.py", line 324, in _get_library
    raise OSError("Failed to load library")

@sbraz
Copy link
Owner

sbraz commented Apr 30, 2021

@joyearnaud I have just pushed a new branch with more verbose exceptions when the library cannot be loaded, can you try it with

pip install git+https://github.com/sbraz/pymediainfo@library_detection

And let me know what the exception looks like now? It should show something like this with the paths that were tested:

OSError: Failed to load library from /usr/local/lib/libmediainfo.dylib - /usr/local/lib/libmediainfo.dylib: <some error here>

@joyearnaud
Copy link

joyearnaud commented May 1, 2021

Thank for your prompt answer @sbraz

Just to be precise, I'm using Apple Silicon architecture;

My PATH

% echo "$PATH"
/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin

Medialib files location

% ls usr/local/lib 
libmediainfo.0.dylib    libmediainfo.dylib
% ls usr/local/bin
libmediainfo.0.dylib    libmediainfo.dylib      mediainfo

Error looks like with new verbose branch

Traceback (most recent call last):
  File "/Users/xxx/Project/filesort/run.py", line 11, in <module>
    sort_files(PATH, length = LENGTH)
  File "/Users/xxx/Project/filesort/filesort/sort_files.py", line 36, in sort_files
    sort_other(filepath, out_repo)
  File "/Users/xxx/Project/filesort/filesort/sort_files.py", line 167, in sort_other
    if is_video(filepath, out_repo):
  File "/Users/xxx/Project/filesort/filesort/sort_files.py", line 157, in is_video
    media_info = MediaInfo.parse(filepath)
  File "/Users/xxx/Library/Python/3.8/lib/python/site-packages/pymediainfo/__init__.py", line 431, in parse
    lib, handle, lib_version_str, lib_version = cls._get_library(library_file)
  File "/Users/xxx/Library/Python/3.8/lib/python/site-packages/pymediainfo/__init__.py", line 329, in _get_library
    raise OSError(
OSError: Failed to load library from libmediainfo.0.dylib, libmediainfo.dylib - dlopen(libmediainfo.0.dylib, 6): no suitable image found.  Did find:
        libmediainfo.0.dylib: no matching architecture in universal wrapper
        /usr/local/lib/libmediainfo.0.dylib: no matching architecture in universal wrapper
        /usr/local/lib/libmediainfo.0.dylib: no matching architecture in universal wrapper
        /Users/xxx/Project/filesort/libmediainfo.0.dylib: no matching architecture in universal wrapper, dlopen(libmediainfo.dylib, 6): no suitable image found.  Did find:
        libmediainfo.dylib: no matching architecture in universal wrapper
        /usr/local/lib/libmediainfo.dylib: no matching architecture in universal wrapper
        /usr/local/lib/libmediainfo.0.dylib: no matching architecture in universal wrapper
        /Users/xxx/Project/filesort/libmediainfo.0.dylib: no matching architecture in universal wrapper

@sbraz
Copy link
Owner

sbraz commented May 1, 2021

I'm no Mac OS expert but it looks like your library isn't compatible with the version you have, do the MediaInfo GUI or the CLI (mediainfo) work?
It looks like you need version 21.03 of the library for Apple Silicon, is that the one you're using?

@joyearnaud
Copy link

I'm no Mac OS expert but it looks like your library isn't compatible with the version you have, do the MediaInfo GUI or the CLI (mediainfo) work?

Seems to work

xxx@MacBook bin % mediainfo /Users/xxx/Data  
General
Complete name                            : /Users/xxx/Data/P1090707.MOV
Format                                   : QuickTime
Format/Info                              : Original Apple specifications
File size                                : 11.4 MiB

It looks like you need version 21.03 of the library for Apple Silicon, is that the one you're using?

xxx@MacBook bin % mediainfo --version            
MediaInfo Command line, 
MediaInfoLib - v21.03

@sbraz
Copy link
Owner

sbraz commented May 1, 2021

I don't think Python 3.8 is supposed to support Apple Silicon (or OSX1 11), where did you get it?
The downloads page for the latest 3.8 release doesn't mention OSX 11 or Apple silicon:
https://www.python.org/downloads/release/python-388/
But the page for 3.9 mentions a specific installer for it:
https://www.python.org/downloads/release/python-394/

Can you try with this newer Python installer please?

@joyearnaud
Copy link

@sbraz I'm brand new Apple user and it's a brand new MacBook: Python 2.xx and Python 3.8 are preinstalled;

Browsing about this version problem show me this article:

This is great, right? Apple says there is a built-in Python 3! And it’s pre-installed? Just move all your scripts to Python 3 and you’ll be fine!

Unfortunately, not quite. The python3 binary does exist on a ‘clean’ macOS, but it is only a stub tool, that will prompt a user to download and install the Command Line Developer Tools (aka “Developer Command Line Tools” or “Command Line Tools for Xcode”). This is common for many tools that Apple considers to be of little interest to ‘normal,’ non-developer users. Another common example is git.

I will definitively try version 3.9 and let you know.

@joyearnaud
Copy link

@sbraz Thank for your time and advice, Python 3.9.4 works fine and resolves my problem

@sbraz
Copy link
Owner

sbraz commented May 1, 2021

You're welcome. Can you tell me if the pymediainfo wheel (which includes libmediainfo) works out-of-the box or if you had to put the dylib somewhere?

Since the lib is built with v20.09, I doubt it'll work. In that case, I might create a new release that includes the newer libmediainfo.

@joyearnaud
Copy link

You're welcome. Can you tell me if the pymediainfo wheel (which includes libmediainfo) works out-of-the box or if you had to put the dylib somewhere?

Since the lib is built with v20.09, I doubt it'll work. In that case, I might create a new release that includes the newer libmediainfo.

First I put everything.

Now with this conf (without dylib)

xxx@MacBook filesort % ls -R /usr/local  
bin	lib

/usr/local/bin:
2to3			easy_install-3.9	idle3.9			pip3			pydoc3			python3			python3.9
2to3-3.9		idle3			mediainfo		pip3.9			pydoc3.9		python3-config		python3.9-config

/usr/local/lib:
 

it's working too.

@sbraz
Copy link
Owner

sbraz commented May 1, 2021

Hmm so the older version did work with Apple Silicon then. Does python -c "from pymediainfo import MediaInfo; print(MediaInfo._get_library())" return something like this?

(<CDLL 'libmediainfo.dylib', handle 5623796306e0 at 0x7f16ae6e7e80>, 94710359423712, '20.09', (20, 9))

@joyearnaud
Copy link

erratum : In my process to make it work I put dylib in my project, that seems to be necessary;

With these dylib in my root working dir

xxx@MacBook filesort % python3 -c "from pymediainfo import MediaInfo; print(MediaInfo._get_library())"
(<CDLL 'libmediainfo.0.dylib', handle 7fb743ca8ad0 at 0x7fb7481361c0>, 140425093475744, '0.7.84', (0, 7, 84))

So, deleting them made running your command fail with

xxx@MacBook filesort % python3 -c "from pymediainfo import MediaInfo; print(MediaInfo._get_library())"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/pymediainfo/__init__.py", line 329, in _get_library
    raise OSError(
OSError: Failed to load library from libmediainfo.0.dylib, libmediainfo.dylib - dlopen(libmediainfo.0.dylib, 6): image not found, dlopen(libmediainfo.dylib, 6): image not found

@sbraz
Copy link
Owner

sbraz commented May 1, 2021

Can we maybe chat on https://gitter.im/ to avoid flooding this issue? I'd like to make it easier for future pymediainfo users to run it on OSX, and from what I see:

  • either you didn't install it from the OSX wheel
  • or the dylib from the wheel doesn't work (but your old 0.7.x one does which would be weird)

EDIT: the issue was that @joyearnaud was still running the library_detection branch (which doesn't contain libmediainfo). After doing pip install --user pymediainfo, the wheel containing libmediainfo was installed and everything worked out-of-the-box.

I have released v5.1.0 which will include the latest library as well as the improved exception messages.

@swannie-eire
Copy link

swannie-eire commented Sep 26, 2022

for anyone else having this issue. I encountered it on 12.5.1 on M1/arm mac.

The only thing that worked for me was downloading the arm64 libmediainfo.0.dylib, libmediainfo.dylib from here https://mediaarea.net/en/MediaInfo/Download/Mac_OS and sticking them into the project

@sbraz
Copy link
Owner

sbraz commented Sep 26, 2022

Hi @swannie-eire so the bundled MediaInfo v21.03 does not work but newer versions do? Can you please try older versions and let me know which version fixed the problem. I'll probably make a new pymediainfo release once I know that this actually fixes the problem.

@JeromeMartinez
Copy link

MediaInfo v21.03 version is with 2 "flavors", one with "old" i386+x86_64 and one with M1 compatible x86_64+arm64, maybe you used i386+x86_64?

@sbraz
Copy link
Owner

sbraz commented Sep 26, 2022

Hi @JeromeMartinez thanks for the feedback, I'll check that. This means I should create two binary packages? One for M1 Macs and one for older CPUs?

@JeromeMartinez
Copy link

One for M1 Macs and one for older CPUs?

No. One for i386 and one for newer CPUs is a lot better, as i386 is maybe for 0.1% (or less!) of your users, it would be less problematic to have an unique build for 99.9% rather that a split between ARM and Intel CPU (still lot of x86_64 users). Or maybe just avoid an i386 version, last macOS with i386 support is 10.6 (11 year old), as we did (v21.09+ are without i386 support, we switched from i386+x86_64 to x86_64+arm64 because in 2021 nearly no one uses new versions of MediaInfo on 10+ year old machines).

but I am surprised that you had no complain about M1/arm compatibility sooner, such machine is very common nowadays, maybe users use pymediainfo with another version of MediaInfo library than yours?
Generally speaking, from MediaInfo upstream point of view we would prefer that you update the "default" (in your repo) version of MediaInfo library is more often updated for taking advantage of the new formats we support, but we also understand that QA would be bigger on your side so this is understandable that you keep using an older version, in that case switching from i386+x86_64 to x86_64+arm64 is the less risky.

sbraz added a commit that referenced this issue Nov 20, 2022
Instead of including the old i386+x86_64 dylib in wheels, we'll now use
the x86_64+arm64 version, following upstream's decision.
More info here:
#24 (comment)
@sbraz
Copy link
Owner

sbraz commented Nov 25, 2022

Thanks for the explanation @JeromeMartinez, I have to admit I kinda forgot that the new CPUs were using a different architecture. I have just released pymediainfo 6.0.0 and I built the wheel using the arm64-compatible libmediainfo → https://files.pythonhosted.org/packages/75/1a/2f018bfe7678fa48e1f4d30b2bba77913bd5145966b405b383e2716093e1/pymediainfo-6.0.0-py3-none-macosx_12_0_x86_64.whl
I also performed the build on a more modern macOS version so the file ends up being named 12_0 instead of 10_9. I hope that won't cause issues to consumers.

EDIT: I ended up using an older macOS version for v6.0.1 (10.15) otherwise pip didn't attempt to install the wheel for pre-12.0 macOS versions.

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