'Why are my DLLs not found despite me importing the path? And can I use VLC in python without installation?
I have written a small program that generates a system tray icon that can play radio streams from a handfull of stations. It is running well for a year now and I tried to update the code and also the instructions of how to compile it with pyinstaller. My goal is to make it generally very easy to use.
While doing so I set up a new development environment with PyCharm with python 3.9 as interpreter. I encountered some problems. Which is actually good, because I wanted to replicate the process of compiling it from scratch.
Using pip, I installed pywin32 and python-vlc in the venv.
I also installed a 64bit version of vlc in C:\Program Files\VLC Plus Player (which seems to be the new standard path).
Now I have two problems. The dll path is not found despite my effort to import it with add_dll_directory. I did not have to do this when I originally wrote the program with an earlier version of Python. (Maybe I set the PATH in Windows.) I would like to rewrite the program now so that no further changes have to be made.
Also, I would like to make the program standalone, removing the need for an installation of VLC for the user. There is a 14 year old thread which indicates that it maybe could be possible to include VLC itelf. Any comments if this might be possible are very welcome!
So far I tried to just putting the dll's into my working directory. This will remove the first problem. But then self.vlc = vlcimp.Instance() will return None, probably because there is no real VLC that can return something.
import sys
import win32ui
import os
os.add_dll_directory(r'C:\Program Files\VLC Plus Player')
import vlc as vlcimp
import win32api
import win32con
import win32gui_struct
import threading
import webbrowser
try:
import winxpgui as win32gui
except ImportError:
import win32gui
class SysTrayIcon(object):
QUIT = 'QUIT'
STOP = 'STOP'
SPECIAL_ACTIONS = [STOP, QUIT]
FIRST_ID = 1023
def __init__(self,
icon,
hover_text,
menu_options,
menu_options2,
on_quit=None,
default_menu_index=None,
window_class_name=None,):
self.button_doubleclicked = False
self.playing = None
self.playingID = ''
self.toggle = False
self.vlc = vlcimp.Instance()
self.player = self.vlc.media_player_new()
self.icon = icon
self.hover_text = hover_text
self.on_quit = on_quit
self.menu = None
The exception when no dll is found is:
Traceback (most recent call last):
File "C:\Users\....py", line 22, in <module>
import vlc as vlcimp
File "C:\Users\...\venv\lib\site-packages\vlc.py", line 210, in <module>
dll, plugin_path = find_lib()
File "C:\Users\...\venv\lib\site-packages\vlc.py", line 170, in find_lib
dll = ctypes.CDLL('.\\' + libname)
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\ctypes\__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\...WORKING_DIRECTORY\libvlc.dll' (or one of its dependencies). Try using the full path with constructor syntax.
Process finished with exit code 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
