ale*_*aka 9 python windows vlc libvlc python-3.x
使用 Python 3.8.0,64 位
操作系统:Windows 10 Pro,版本 10.0.15063 Build 15063,64 位
VLC,3.0.8 Vetinari,64 位
已经通过 PIP 安装了 Python VLC 绑定
VLC 的路径和 libvlc.dll 的直接路径都在我的“PYTHONPATH”和“PATH”环境变量中。
我正在通过 Windows 命令提示符运行我的脚本。
我试图运行的脚本是一行:
import vlc
Run Code Online (Sandbox Code Playgroud)
这是命令提示符告诉我的:
Traceback (most recent call last):
File "001.py", line 1, in <module>
import vlc
File "C:\Program Files\Python38\lib\site-packages\vlc.py", line 207, in <module>
dll, plugin_path = find_lib()
File "C:\Program Files\Python38\lib\site-packages\vlc.py", line 163, in find_lib
dll = ctypes.CDLL(libname)
File "C:\Program Files\Python38\lib\ctypes\__init__.py", line 369, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libvlc.dll'. Try using the full path with constructor syntax.
Run Code Online (Sandbox Code Playgroud)
我是 Python 新手,任何帮助将不胜感激!
From the Python 3.8 release notes:
DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution. If your application relies on these mechanisms, you should check for add_dll_directory() and if it exists, use it to add your DLLs directory while loading your library. Note that Windows 7 users will need to ensure that Windows Update KB2533623 has been installed (this is also verified by the installer).
PATH
or cwd cannot be used any more unless you specifically add these directories to the dll search path.
To add cwd to search path:
import os
os.add_dll_directory(os.getcwd())
Run Code Online (Sandbox Code Playgroud)
大多数库都提供了一个环境变量来指定 dll 位置。这将使用路径加载dll,这是有效的。
许多包将不得不为 py38 清理它们的库加载并决定如何处理这个问题。它目前是很多混乱的根源。
小智 5
添加安装 VLC 播放器的目录,而不是当前目录。
就我而言:
import os
os.add_dll_directory(r'C:\Program Files\VideoLAN\VLC')
import vlc
Run Code Online (Sandbox Code Playgroud)
我想指出的是,2020 年有可能访问vlc-website,通过单击下载,您将下载32 位版本的VLC——即使现在几乎每个操作系统都是 64 位。
在这种情况下 libvlc.dll
不会被发现。
确保安装64 位版本: https //get.videolan.org/vlc/3.0.11/win64/vlc-3.0.11-win64.exe
无需更改代码。