0

I am trying to use the python-vlc library in python and keep getting errors when using "import vlc".

I have the 64-bit Windows version of VLC player installed, and am using Python version 3.9.6 in a virtual environment in Visual Studio. My version of Windows is also 64-bit.

I used "pip install python-vlc" to download the module from the terminal within the project's virtual environment and confirmed that it downloaded correctly.

Here's the code I'm using:

try:
    import vlc
except:
    from os import environ
    vlc_path = 'C:\Program Files\VideoLAN\VLC'
    environ['PATH'] += ';' + vlc_path
    import vlc

When running this in Visual Studio I get the error:

No module named 'vlc'

Any help would be greatly appreciated.

Thanks a lot.

Josh
  • 1,556
  • 1
  • 10
  • 21
ScottHJ
  • 5
  • 5
  • Are there supposed to be spaces in file directory names? – LuckElixir Aug 28 '21 at 18:19
  • @thirdsandfourths are you referring to the space in "Program Files" (i.e. "C:\Program Files\VideoLAN\VLC") ? That's how the directory path appears in my windows browser and how I've seen this code suggested in other threads. Not sure if that's what you meant. – ScottHJ Aug 28 '21 at 18:27
  • Does this answer your question? [How to import a module given the full path?](https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path) – sahasrara62 Aug 28 '21 at 18:29
  • Did you choose the correct virtual environment in VS code? Maybe [this](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment) helps – suvayu Aug 28 '21 at 18:30
  • should it be pip3 install python-vlc – viky.pat Aug 28 '21 at 18:39
  • @suvayu now that you mention it, when I inspect the directory: "project\env\Lib\site-packages" (which is where I assume the downloaded package (python-vlc) should be, I don't see it there. But when I downloaded (pip install python-vlc) via the terminal, I confirmed that the command line was launching from the correct env. – ScottHJ Aug 28 '21 at 18:39
  • Can you import it in the Python REPL in the terminal? If you can, then look for the `vlc.__file__` attribute. That should tell you where it is installed. – suvayu Aug 28 '21 at 18:41
  • @ScottHJ Yes and what I mean is that the space might cause an error. – LuckElixir Aug 28 '21 at 23:47

1 Answers1

0

You can install library locally by doing pip install -t . python-vlc --no-user and try to import it (you will download a vlc.py file to your project folder and you can try to import it)

pedro_bb7
  • 1,601
  • 3
  • 12
  • 28
  • This worked. Thank you very much. I'm now having trouble with my first implementation --playing a video file-- but at least "import vlc" seems to be working now. Thank you!!! – ScottHJ Aug 28 '21 at 19:08
  • Could you please mark my answer as solution please? This way I can get some karma – pedro_bb7 Aug 28 '21 at 22:17