首先,我知道有人问过类似的问题,但我无法找到解决我的问题的方法。谢谢您的帮助!
我一直在尝试使用 pyinstaller 创建可执行文件,但无法让 pyinstaller 找到 libvlc 的 .dll。特别是:libvlc.dll 和 libvlccore.dll。这些位于我的 VideoLAN\VLC 目录中,但我还将所有 dll 从我的 VideoLAN\VLC 目录复制到我的 Compile 目录中,位于我的 test.py 和 test.spec 文件旁边。我还将 VideoLAN\VLC 目录添加到我的环境变量中,试图帮助 pyinstaller 找到它们。 尽管如此,当我运行 pyinstaller test.spec 时,我收到此警告:
48352 WARNING: lib not found: libvlccore.dll dependency of C:\Users\chipc\Desktop\Code\Python\KivyTest\KivyTut\Compile\libvlc.dll
其余的编译日志可以在这里看到:https://pastebin.com/DJmkQ7nm
当尝试运行生成的 test.exe 时,它给了我这个:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 149, in __init__
File "ctypes\__init__.py", line 356, in __init__
OSError: [WinError 193] %1 is not a valid Win32 application
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 18, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\chipc\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\vlc.py", line 207, in <module>
File "site-packages\vlc.py", line 163, in find_lib
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 151, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll 'C:\\Users\\chipc\\Desktop\\Code\\Python\\KivyTest\\KivyTut\\Compile\\dist\\test\\libvlc.dll'. Most probably this dynlib/dll was not found when the application was frozen.
[16044] Failed to execute script test
此外,生成的包含test.exe的文件夹中确实有libvlc.dll。
这是我的 test.spec 文件:
# -*- mode: python ; coding: utf-8 -*-
from kivy_deps import sdl2, glew
block_cipher = None
a = Analysis(['test.py'],
pathex=[('C:\\Users\\chipc\\Desktop\\Code\\Python\\KivyTest\\KivyTut\\Compile'), ('C:\Program Files\VideoLAN\VLC')],
binaries=[('./libvlc.dll', '.'), ('./axvlc.dll', '.'), ('./libvlccore.dll', '.'), ('./npvlc.dll', '.')],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
a.datas += Tree('C:\\Program Files\\VideoLAN\\VLC\\plugins', prefix='plugins')
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='test',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe, Tree('C:\\Users\\chipc\\AppData\\Local\\Programs\\Python\\Python37-32\\Lib\\site-packages\\kivy_deps'),
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=True,
name='test')
该程序在 PyCharm 中运行。如何让 pyinstaller 找到 libvlc.dll?
以防万一,这是我的编译目录的样子:
axvlc.dll
libvlc.dll
libvlccore.dll
npvlc.dll
test.py
test.spec
感谢您的帮助,我这几天一直在努力解决这个问题!
我有同样的问题,我删除了vlc应用程序和vlc模块,问题是因为vlc应用程序适用于32位而我的电脑是64位,然后安装了64位vlc应用程序,然后再次下载了vlc模块并添加了libvlc的路径。 dll 到系统变量,一切顺利......
这是我的 Google 搜索中不断出现的没有答案的堆栈帖子之一。
您是否尝试过将
libVLC.dll
添加到二进制文件行中,如下所示:
a.binaries + [("libVLC.dll", "D:\KivySchool\VLC\libvlc.dll", "BINARY")],
我看到这行
exclude_binaries=True,
,也许删除它?我的工作规范文件中没有该行。
示例测试.py
from sys import platform
if platform == "win32": #https://docs.python.org/3/library/sys.html#sys.platform
import vlc
import os
import time
vlc_player = vlc.MediaPlayer()
medianame = "bigbuckbunny x265.mp4"
mediapath = os.path.join(os.path.dirname(__file__), medianame)
media = vlc.Media(mediapath)
vlc_player.set_media(media)
vlc_player.play()
offset = 5
time.sleep(offset)
length = vlc_player.get_length() #time in ms (divide by 1000 to get in seconds)
newoffset = length/1000 - offset
time.sleep(newoffset)
示例规格文件
# -*- mode: python ; coding: utf-8 -*-
medianame = "bigbuckbunny x265.mp4"
a = Analysis(
['basicpyvlc.py'],
pathex=["D:\KivySchool\VLC"],
binaries=[("D:\KivySchool\VLC\plugins\*", "plugins")],
datas=[(medianame, ".")],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries + [("libVLC.dll", "D:\KivySchool\VLC\libvlc.dll", "BINARY")],
a.datas,
[],
name='basicvlc',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
适用于:Win 10、x64 VLC、PyInstaller 6.3.0