chrippa / livestreamer

Command-line utility that extracts streams from various services and pipes them into a video player of choice. No longer maintained, use streamlink or youtube-dl instead.
http://livestreamer.io/
BSD 2-Clause "Simplified" License
3.88k stars 582 forks source link

Livestreamer libs not working with py2exe #984

Open ceejayc7 opened 9 years ago

ceejayc7 commented 9 years ago

Making a simple script and trying to create an executable out of it.

test.py

import livestreamer

stream = livestreamer.streams("http://www.twitch.tv/nl_kripp")
print stream

setup.py

from distutils.core import setup
import py2exe

setup(console=[{"script":"test.py"}],options={"py2exe":{"includes":["livestreamer"]}})

From cmdline:

python setup.py py2exe

No errors occur, executable is generated, but the following error happens when running test.exe

Traceback (most recent call last):
  File "test.py", line 3, in <module>
  File "livestreamer\api.pyc", line 12, in streams
  File "livestreamer\session.pyc", line 354, in streams
  File "livestreamer\session.pyc", line 344, in resolve_url
livestreamer.exceptions.NoPluginError
ceejayc7 commented 9 years ago

With a bit of further digging, it seems that py2exe isn't compiling the plugins inside of livestreamer/plugins/* which would most likely be why this error is occuring.

With that in mind, how would i force py2exe to compile all of the plugins available to livestreamer?

ghost commented 9 years ago

Nightly builds are available too. Or is there any other reason, why you are trying to compile it from source?

ceejayc7 commented 9 years ago

I'm actually creating a separate project that lists a bunch of streams which are live using the livestreamer.streams call across various streaming websites. My test.py script was just a way to pinpoint the py2exe problem that I was having.

I did figure out a way to force py2exe to compile the various plugins by using the following inside my setup.py

setup(console=[{"script":"test.py"}],options={"py2exe":{"includes":["livestreamer.plugins.*"]}})

After running py2exe and running the executable, I'm getting this error:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
  File "livestreamer\api.pyc", line 11, in streams
  File "livestreamer\session.pyc", line 65, in __init__
  File "livestreamer\session.pyc", line 363, in load_builtin_plugins
  File "livestreamer\session.pyc", line 373, in load_plugins
ImportError: No module named afreeca
Nattefrost commented 8 years ago

Same ImportError as ceejayc7 using cx_Freeze with python3. livestreamer_exe_bug

rctgamer3 commented 8 years ago

I've managed to find a workaround/possible fix.

The reason livestreamer runs into livestreamer.exceptions.NoPluginError is because py2exe bundles all packages in a zip file, Library.zip, thus livestreamer cannot access its modules correctly.

The reason it can't find afreeca is because it is the very first module/site plug-in aka can't load any of the site plug-ins.

Here's my setup.py. setup(script_args = ['py2exe'], console = [{ 'script': 'script.py' }], options = { 'py2exe': { "compressed": 0, "skip_archive": True, 'optimize': 0, "packages": ["livestreamer", "livestreamer_cli"], "includes": ["livestreamer", "livestreamer.plugin", "livestreamer.plugins.*"] } })`

("packages" and "includes" might not be needed) "compressed": 0 forces py2exe to not compress the zip file. "skip_archive" skips creation of the zip file altogether.

This allowed livestreamer to work. However, I now have second issue, I cannot get a window/GUI generated by opencv (cv2) to work by launching a py2exe-generated exe. Might just be a bug in my own code or with opencv, although it might be worth mentioning.

Nattefrost commented 8 years ago

Thanks for replying after so much time, i am myself using pyinstaller and/or cx_freeze so i'll try your method in the following days/weeks and i'll let you know. =)