FileNotFoundError: Could not find module 'libvlc.dll'

alexacallmebaka picture alexacallmebaka · Nov 24, 2019 · Viewed 12.1k times · Source

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!

Answer

Grimmy picture Grimmy · Nov 24, 2019

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.