How can I convince PyInstaller, via my spec file, to include libvlc.dll in the EXE it makes?

pyinstaller spec file
pyinstaller add-data
pyinstallerimporterror: failed to load dynlib/dll
pyinstaller modulenotfounderror
pyinstaller hidden imports

I can create an EXE with PyInstaller that works on my machine. I labor in hopefulness, not delusion, I hope, that the EXE really is self-contained. However, the EXE does NOT run on other machines. It chokes due to the absence of libvlc.dll, which the error message says is probably due to PyInstaller's apparent inability to find it. I have tried several things with the spec file, all to no avail. I haven't included any code because I don't think this is germane. Here's my spec file:

# -*- mode: python -*-

block_cipher = None

added_files = [
     ( "D:/Applications/Python/Rogues Gallery/images/*.*", "images"),
     ( "D:/Applications/Python/Rogues Gallery/videos/*.*", "videos"),
     ( "D:/Applications/Python/MyMediaPlayer/icons/*.*", "icons")
     ]

a = Analysis(["Rogues_Gallery.py"],
         pathex=["D:/Applications/Python/Rogues Gallery/Rogues Gallery",
                 "C:/Program Files/VideoLAN/VLC/"],
         binaries=[("C:/Program Files/VideoLAN/VLC/plugins/*", "plugins"),
                   ("C:/Program Files/VideoLAN/VLC/libvlc.dll", ".")],
         datas=added_files,
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)

exe = EXE(pyz,
      a.scripts,
      a.binaries,
      a.zipfiles,
      a.datas,
      name="Rogues_Gallery",
      debug=True,
      strip=False,
      upx=False,
      runtime_tmpdir=None,
      console=True )

Running PyInstaller on this spec file produces an accounting that includes these lines:

1677 WARNING: One binary added with two internal names.
1677 WARNING: ('libvlc.dll', 'C:\\Program Files\\VideoLAN\\VLC\\libvlc.dll', 'BINARY')
1678 WARNING: was placed previously at
1678 WARNING: ('libvlc.dylib', 'C:\\Program Files\\VideoLAN\\VLC\\libvlc.dll', 'BINARY')

By the way, what's a "dylib" file? Isn't this a MAC thing and what's it doing on my PC? Actually, I can't find a "dylib" file on my PC, except as a result of the PyInstaller build; that is, there's one, libvlc.dylib, in the MEIPASS temporary folder when I run the EXE; there is also libvlc.dll. It appears to be something PyInstaller is creating. If I omit ("C:/Program Files/VideoLAN/VLC/libvlc.dll", "."), I don't get the warnings and libvlc.dll is NOT present in the temp file. Strangely, the EXE continues to work so libvlc.dll is lurking somewhere. This begs the question: "Is the EXE really self-contained or is it fishing outside itself, to get what it lacks from the host?" Maybe, this is why it works on my machine and NOT on other computers that don't have libvlc.dll at all, anywhere.

For what it's worth, here are my Rogues Gallery imports:

try:
    import tkinter     as tk
    import tkinter.ttk as ttk
except ImportError:
    import tkinter as tk
    import ttk

from tkinter.filedialog import askopenfilename
from tkinter import messagebox
from tkinter.constants import *
from PIL import Image, ImageTk

import os
import sys
import pathlib
import random
from datetime import datetime
import time
import vlc
import MyMediaPlayer

"import vlc" doesn't need to be there, but I left it because this is just the way I have been running; it should come out. Rogues Gallery itself doesn't do any vlc stuff. MyMediaPlayer.py is my Python script. This is where all the vlc stuff happens. Here are its imports:

try:
    import tkinter     as tk
    import tkinter.ttk as ttk
except ImportError:
    import tkinter as tk
    import ttk

from tkinter.filedialog import askopenfilename
from tkinter import messagebox
from tkinter.constants import *
from PIL import Image, ImageTk

import os
import sys
import vlc
import pathlib
import atexit
from threading import Thread, Event
import time
import platform

I have tried everything I can think of. I need other, better thinkers.

I'm not an expert with PyInstaller and I get the same warning on a Qt dll that I explicitly include. However, my exe runs on other computers. Does your code add sys._MEIPASS to the python-vlc search path for libvlc.dll? Something to the affect of:

# handle pyInstaller temp directory 
if hasattr(sys, '_MEIPASS'):
    # add to your python-vlc search path

Does the machine you're testing on have VLC installed? Can you give the exact error you're seeing when trying to run on the other machine?

Using Spec Files — PyInstaller 3.6 documentation, The spec file tells PyInstaller how to process your script. When you want to include run-time libraries ( .dll or .so files) that PyInstaller does not know An instance of EXE is built from the analyzed scripts and the PYZ archive. This means that any changes a one-file executable makes to an added file will be lost when the� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Success! Using PyInstaller 3.3.1 (and Python 3.6.4) I have created an EXE that works on my machine and those of others, which may differ from mine (different OS, no VLC stuff, etc.). The answer to this last question turned out to be SIMPLE but not EASY to find. This was true for EVERY question I had on my Python journey, starting from zero to this crossing of the finish line of my first Python project. The solution is properly configuring the spec file with regard to VLC. I still don't know enough to understand or explain but here's the working spec file. It can speak for itself. Maybe, an expert can explain so others won't have to go through what I did.

# -*- mode: python -*-

block_cipher = None

added_files = [
               ("D:/Applications/Python/RoguesGallery/images/*.*", "images"),
               ("D:/Applications/Python/RoguesGallery/videos/*.*", "videos"),
               ("D:/Applications/Python/MyMediaPlayer/icons/*.*", "icons")
              ]

a = Analysis(['RoguesGallery.py'],
         pathex=["C:/Program Files/VideoLAN/VLC/"],
         binaries=[("C:/Program Files/VideoLAN/VLC/plugins/*", "plugins")],
         datas=added_files,
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)

exe = EXE(pyz,
      a.scripts,
      a.binaries + [("libVLC.dll", "C:/Program Files/VideoLAN/VLC/libvlc.dll", "BINARY")],
      a.zipfiles,
      a.datas,
      name='RoguesGallery',
      debug=False,
      strip=False,
      upx=False,
      runtime_tmpdir=None,
      console=False)

I used tkinter for this project. I will use PyQt5 for future projects. I'm already using it. Watch this video. Emacs and Unix people like me will have fun. https://www.youtube.com/watch?v=ON0A1dsQOV0

I can provide the source, too, if anybody wants to take it out for a spin. If you're trying to get up to speed on displaying images or "playing" a file or GUI stuff, my little project might help you. It includes lots of didactic experimental digressions, how to do this, how to do that kind of stuff. My next project is to translate this very project from tkinter to PyQt5. Keep Coding!

Python-VLC exe video not playing � Issue #4369 � pyinstaller , After i compile my app the video is not playing (remains in black screen). Also make sure you have the latest vlc player (32bit) installed on PycharmProjects\ root\VLC\libvlc.dll Don't forget to add "VLC" folder to .spec file, like this: also convince management and others to support those than python,� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

I had the same problem, you'll be surprised what I did to make it work.

I took all the files from: C:\Program Files\VideoLAN\VLC and loaded them to the dist folder D:\Users\myprojects\python\musicPlayer\dist\main.

The reason, pyinstaller failed to transfer some VLC libraries at compiling time.

So I just took them all without filtering. I'm sure I added some unnecessary files too, but it works so I don't really care. You can go through them one by one if you want, I just loaded all

如何通过我的规范文件说服PyInstaller在其生成的EXE中包含libvlc.dll?, How can I convince PyInstaller, via my spec file, to include libvlc.dll in the EXE it makes? 发表于 2018-01-19 08:35:49. 活跃于 2019-11-11 01:07:46. 查看1599 次. Stack Overflow | The World’s Largest Online Community for Developers

python, _MEIPASS a python-VLC keres�si �tvonala libvlc.dll? Valamit az befoly�solja a: # handle pyInstaller temp directory if hasattr(sys, '_MEIPASS'): # add to your python-vlc Haszn�lata PyInstaller 3.3.1 (�s Python 3.6.4) hoztam l�tre egy EXE , hogy Vettem az �sszes f�jlt: C:\Program Files\VideoLAN\VLC terhelt őket a dist�

python 3x, The error message as a result of executing the generated exe file is as follows. PyInstallerImportError: Failed to load dynlib/dll 'libvlc.dll'. question itself, it may be missing information, so please add it if you point it out.) i want to make a beep sound periodically by using python on raspberry pi � about�

Error while running the exe file made with pyinstaller - Python, dll and put it in the same folder as exe. Perhaps the libvlc file will be in vlc install folder. 2.

Comments
  • If you are not sure of the answer , Please add comments
  • Yes, my program uses _MEIPASS. I think VLC is installed on all computers involved, but should this matter?
  • Traceback (most recent call last): File "Rogues_Gallery.py", line 23, in <module> File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  • File "d:\Downloads\PyInstaller\PyInstaller-3.3\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module File "site-packages\vlc.py", line 198, in <module> File "site-packages\vlc.py", line 173, in find_lib File "PyInstaller\loader\pyiboot01_bootstrap.py", line 151, in init main.PyInstallerImportError: Failed to load dynlib/dll 'libvlc.dll'. Most probably this dynlib/dll was not found when the application was frozen. [9084] Failed to execute script Rogues_Gallery