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

Import error on MacOS #37

Closed
joejacobs opened this issue Feb 3, 2018 · 11 comments
Closed

Import error on MacOS #37

joejacobs opened this issue Feb 3, 2018 · 11 comments

Comments

@joejacobs
Copy link

joejacobs commented Feb 3, 2018

Importing libvlc doesn't work on MacOS. When I try to import VLC (using VLC 3.0 RC9) I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/user/miniconda/envs/blah/lib/python3.6/site-packages/vlc.py", line 198, in <module>
    dll, plugin_path  = find_lib()
  File "/Users/user/miniconda/envs/blah/lib/python3.6/site-packages/vlc.py", line 183, in find_lib
    dll = ctypes.CDLL(p)
  File "/Users/user/miniconda/envs/blah/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib, 6): Library not loaded: @rpath/libvlccore.dylib
  Referenced from: /Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib
  Reason: image not found

It looks like libvlccore.dylib needs to be imported first before importing libvlc.dylib.

@oaubert
Copy link
Owner

oaubert commented Feb 6, 2018

I do not have a Mac at hand to test this, but I would tend to say that this dynamic linker issue should be reported to upstream VLC. I used to solve such issues with install_name_tool some years ago.
Maybe @mrJean1 (who develops on Mac) can give some hints?

@mrJean1
Copy link
Collaborator

mrJean1 commented Feb 6, 2018

Where can I find VLC 3.0 RC9? What is environment variable [DY]LD_LIBRARY_PATH set to?

There is no problem with VLC 2.2.8 and python-vlc/generated/3.0/vlc.py using Python 2.7.14 and 3.6.4 on macOS 10.13.3 High Sierra.

Btw, if VLC 3+ does load multiple *.dylib's, perhaps [DY]LD_LIBRARY_PATH should be set, e.g. to the directory where libvlc.dlib is found?

@mrJean1
Copy link
Collaborator

mrJean1 commented Feb 6, 2018

Using this VLC 3.0 RC9 build, the error is the same (for Python 2.7.14 and 3.6.4):

% python vlc.py 
Traceback (most recent call last):
  File "vlc.py", line 198, in <module>
    dll, plugin_path  = find_lib()
  File "vlc.py", line 183, in find_lib
    dll = ctypes.CDLL(p)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 366, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib, 6): Library not loaded: @rpath/libvlccore.dylib
  Referenced from: /Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib
  Reason: image not found

Both .dylib's are there and the VLC 3.0 RC9 App works just fine. It Looks like an issue with the libvlc.dylib. Does the VLC App even load that libvlc.dylib?

% ls -al /Applications/VLC.app/Contents/MacOS/lib/
total 2680
drwxr-xr-x@ 6 jean  admin      204 Feb  5 23:11 .
drwxr-xr-x@ 7 jean  admin      238 Feb  5 23:11 ..
-rwxr-xr-x@ 1 jean  admin   180276 Feb  5 23:11 libvlc.5.dylib
lrwxr-xr-x  1 jean  admin       14 Feb  5 23:11 libvlc.dylib -> libvlc.5.dylib
-rwxr-xr-x@ 1 jean  admin  1179516 Feb  5 23:11 libvlccore.9.dylib
lrwxr-xr-x  1 jean  admin       18 Feb  5 23:11 libvlccore.dylib -> libvlccore.9.dylib

% ls -al /Applications/VLC2.2.8.app/Contents/MacOS/lib/
total 2200
drwxr-xr-x@ 6 jean  admin     204 Nov 22 17:06 .
drwxr-xr-x@ 8 jean  admin     272 Nov 22 17:06 ..
-rw-r--r--@ 1 jean  admin  124256 Nov 22 17:06 libvlc.5.dylib
lrwxr-xr-x  1 jean  admin      14 Nov 22 17:06 libvlc.dylib -> libvlc.5.dylib
-rw-r--r--@ 1 jean  admin  989104 Nov 22 17:06 libvlccore.8.dylib
lrwxr-xr-x  1 jean  admin      18 Nov 22 17:06 libvlccore.dylib -> libvlccore.8.dylib

However, the following command line does not show the error:

% env DYLD_LIBRARY_PATH=/Applications/VLC.app/Contents/MacOS/lib/ python vlc.py
Usage: vlc.py [options] <movie_filename>
Once launched, type ? for help.

Build date: Thu Jan  4 23:45:25 2018 3.0.0 (0x3006500)
LibVLC version: 3.0.0-rc9 Vetinari (0x0)
LibVLC compiler: clang: warning: argument unused during compilation: '-mmacosx-version-min=10.7' [-Wunused-command-line-argument]
Plugin path: /Applications/VLC.app/Contents/MacOS/plugins

Modifying vlc.py as follows does not solve the problem:

    ....
    elif sys.platform.startswith('darwin'):
        # FIXME: should find a means to configure path
        d = '/Applications/VLC.app/Contents/MacOS/'
        e = 'DYLD_LIBRARY_PATH'
        if e in os.environ:
             os.environ[e] = d + 'lib:' + os.environ[e]
        else:
             os.environ[e] = d + 'lib'
        p = d + 'lib/libvlc.dylib'
        ....

Neither does setting PYTHON_VLC_LIB_PATH and PYTHON_VLC_MODULE_PATH.

But changing vlc.py as follows does work:

    ....
    elif sys.platform.startswith('darwin'):
        # FIXME: should find a means to configure path
        d = '/Applications/VLC.app/Contents/MacOS/'
        p = d + 'lib/libvlc.dylib'
        if os.path.exists(p):
            # force pre-load of libvlccore.dylib  # ****
            ctypes.CDLL(d + 'lib/libvlccore.dylib')  # ****
            dll = ctypes.CDLL(p)
            for p in ('modules', 'plugins'):
                ...

@oaubert
Copy link
Owner

oaubert commented Feb 14, 2018

Great work Jean. Could you submit a patch with this modification (so that authorship is preserved)?

@mrJean1
Copy link
Collaborator

mrJean1 commented Feb 14, 2018 via email

@oaubert
Copy link
Owner

oaubert commented Feb 14, 2018

Something must have changed in the macosx build chain. The extras/package/macosx directory of VLC has had lots of changes these last months. I would even expect that videolan/vlc@f6e51b0 (and the following one removing build-package.sh) look like the ones that could have introduced the issue.

@mrJean1
Copy link
Collaborator

mrJean1 commented Feb 14, 2018 via email

@oaubert
Copy link
Owner

oaubert commented Feb 16, 2018

I don't see the patch. Where did you submit it?

@mrJean1
Copy link
Collaborator

mrJean1 commented Feb 16, 2018 via email

@smilemcm
Copy link

smilemcm commented Jun 19, 2020

in my case, there is no C library in my system..
so I installed the vlc application through apple store.
in my case application directory is "/Applications/VLC 2.app/Contents/MacOS/lib"
so i open vlc.py file in python lib,
I change the directory name like below

  # elif sys.platform.startswith('darwin'):
        # FIXME: should find a means to configure path
        #d = '/Applications/VLC.app/Contents/MacOS/'.        <- origin directory name
       d = '/Applications/VLC 2.app/Contents/MacOS/'.        <- my system directory
        c = d + 'lib/libvlccore.dylib'
        p = d + 'lib/libvlc.dylib'
        if os.path.exists(p) and os.path.exists(c):
            # pre-load libvlccore VLC 2.2.8+
            ctypes.CDLL(c)
            dll = ctypes.CDLL(p)

@AccelQuasarDragon
Copy link

Just a quick note because this thread keeps popping up on my google searches:

If you are packaging with pyinstaller for Mac, VLC.app MUST be installed in the applications folder for it to work smoothly.

If VLC is not in the applications folder (for example you want your .app to work regardless if the user has previously installed VLC), you must add libvlccore.dylib and libvlc.dylib manually in the spec file, and modify vlc.py to search in the _MEIPASS folder:

adding dylibs in the .spec file

a.binaries + [
        ("libvlc.dylib", "/Users/KivySchool/CODING/BasicPyVLC/VLC.app/Contents/MacOS/lib/libvlc.dylib", "BINARY"),
        ("libvlccore.dylib", "/Users/KivySchool/CODING/BasicPyVLC/VLC.app/Contents/MacOS/lib/libvlccore.dylib", "BINARY")
        ],

vlc.py changed to look in sys._MEIPASS folder

elif sys.platform.startswith('darwin'):
    d = sys._MEIPASS
    c = os.path.join(d, "libvlccore.dylib")
    p = os.path.join(d, "libvlc.dylib")
    print("paths exists and loaded?", c, p, os.path.exists(p), os.path.exists(c))
    if os.path.exists(p) and os.path.exists(c):
        # pre-load libvlccore VLC 2.2.8+
        ctypes.CDLL(c)
        dll = ctypes.CDLL(p)
        for p in ('modules', 'plugins'):
            p = os.path.join(d, p)
            if os.path.isdir(p):
                plugin_path = p
                print("pluginpath", plugin_path, os.path.exists(plugin_path))
                break

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

5 participants