FileNotFoundError: Could not find module 'libvlc.dll'

走远了吗. 提交于 2020-06-26 06:57:58

问题


Using Python 3.8.0, 64 bit

OS: Windows 10 Pro, Version 10.0.15063 Build 15063, 64 bit

VLC, 3.0.8 Vetinari, 64 bit

Have installed Python VLC Bindings through PIP

The path to VLC and the direct path to libvlc.dll are both in my “PYTHONPATH” and “PATH” environment variables.

I am running my script via the Windows command prompt.

The script i'm trying to run is one line:

import vlc

Here is what the command prompt is telling me:

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.

I'm new to Python, any help would be greatly appreciated!


回答1:


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())

Most libraries offer an environment variable to specify the dll location. That would load the dll with with the path, something that work.

A lot of packages will have to clean up their library loading for py38 and decide how to handle this. It's currently a source for a lot of confusion.




回答2:


Instead of current directory, add the directory where VLC player is installed.

In my case:

import os
os.add_dll_directory(r'C:\Program Files\VideoLAN\VLC')

import vlc



回答3:


I download VLC 3.0.7 in case my version of python-vlc is 3.0.7110, then I copy plugins,libvlc.dll and libvlccore.dll to C:\Windows\System32, notes that if your python is 64bit, you need vlc 64bit as well



来源:https://stackoverflow.com/questions/59014318/filenotfounderror-could-not-find-module-libvlc-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!