Ape / samsungctl

Remote control Samsung televisions via a TCP/IP connection
MIT License
713 stars 191 forks source link

Windows compatibility #31

Closed AnderssonPeter closed 7 years ago

AnderssonPeter commented 7 years ago

Im running on windows and followed your instructions:

  1. pip install samsungctl
  2. python -m samsungctl

I get the following error from 2.

Traceback (most recent call last):
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\samsungctl\__main__.py", line 11, in <module>
    from . import interactive
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\samsungctl\interactive.py", line 1, in <module>
    import curses
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\curses\__init__.py", line 13, in <module>
    from _curses import *
ModuleNotFoundError: No module named '_curses'

What am i doing wrong?

Python version 3.6.0

Ape commented 7 years ago

Curses is used for the interactive mode (samsungctl -i). I am afraid it's not available for Windows.

Please test if #32 fixes this issue for you. The pull request makes curses optional, so that you can use everything else except the interactive mode even without it.

AnderssonPeter commented 7 years ago

i tried it and got the following error instead ran py -m samsungctl and py -m samsungctl --host 192.168.0.23 --port 8001 --method websocket key KEY_VOLUP both gave the error..

Traceback (most recent call last):
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\xbmc\Downloads\samsungctl-pr-optional_curses\samsungctl\__main__.py", line 122, in <module>
    main()
  File "C:\Users\xbmc\Downloads\samsungctl-pr-optional_curses\samsungctl\__main__.py", line 92, in main
    config = _read_config()
  File "C:\Users\xbmc\Downloads\samsungctl-pr-optional_curses\samsungctl\__main__.py", line 30, in _read_config
    directories.append(os.path.join(os.getenv("HOME"), ".config"))
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\ntpath.py", line 75, in join
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType
Ape commented 7 years ago

So I guess os.getenv("HOME") returns None. I'm not surprised that it's not set on Windows, but might be that it's sometimes not available even on Linux (although usually it is). So this needs to be fixed. I'll make a pull request.

However, to properly support Windows and other operating systems, we should replace the whole config path list with something more generic or make OS specific paths.

AnderssonPeter commented 7 years ago

I would help but i have only written like 20 lines of python (i find dynamic languages somewhat confusing), but i'm happy to test any changes you make.

But yes if i open py and write

import os
str(os.getenv("HOME"))

it outputs 'None'.

If i understand correctly os.getenv tries to read a environment variable? On windows i think we have a few diffrent alternatives where you can store configuration data.

Ape commented 7 years ago

I made #35 to fix this. Could you check how it works in Windows? Are the system-wide and user specific paths correct / meaningful in Windows?

AnderssonPeter commented 7 years ago

Ill try it out later when i get home, i don't have a samsung tv at work.

I don't know if the Paths are correct or meaningful, i tried to run import appdirs in my python console but it just gave me ModuleNotFoundError: No module named 'appdirs' so i can't check what appdirs.user_config_dir() and appdirs.site_config_dir(title) resolve into on windows.

But when looking at the documentation for appdirs 1.4.3 it seems they will be stored in C:\Users\<User>\AppData\Local\<AppName> and that seems like good place as any.

AnderssonPeter commented 7 years ago

i tried and got the following result

py -m samsungctl --name test --host 192.168.0.23 --port 8001 --method websocket KEY_VOLUP
Traceback (most recent call last):
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\xbmc\Downloads\samsungctl-pr-appdirs\samsungctl\__main__.py", line 1, in <module>
    import appdirs
ModuleNotFoundError: No module named 'appdirs'
Ape commented 7 years ago

You need to have appdirs installed. Try pip install appdirs.

AnderssonPeter commented 7 years ago

Ok that solves that error, then i got the same error but for websocket so i installed that 2. Now i get the following error:

py -m samsungctl --name test --host 192.168.0.23 --port 8001 --method websocket KEY_VOLUP
Traceback (most recent call last):
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\xbmc\Downloads\samsungctl-pr-appdirs\samsungctl\__main__.py", line 119, in <module>
    main()
  File "C:\Users\xbmc\Downloads\samsungctl-pr-appdirs\samsungctl\__main__.py", line 97, in main
    with Remote(config) as remote:
  File "C:\Users\xbmc\Downloads\samsungctl-pr-appdirs\samsungctl\remote.py", line 10, in __init__
    self.remote = RemoteWebsocket(config)
  File "C:\Users\xbmc\Downloads\samsungctl-pr-appdirs\samsungctl\remote_websocket.py", line 21, in __init__
    self.connection = websocket.WebSocket()
TypeError: __init__() missing 3 required positional arguments: 'environ', 'socket', and 'rfile'

Edit: this is the exact same error i get in Home Assistant but i guess thats understandable as it uses this component.

Ape commented 7 years ago

Do you have websocket-client installed? Which version is it? You may need to uninstall websocket.

AnderssonPeter commented 7 years ago

I had websocket (0.2.1) installed, uninstalled it and installed websocket-client instead and the error went away! now everything is working properly!

Thanks for your patience with me!

Bakipl commented 6 years ago

Hi had exactly the same issue with getting HOME dir on windows, i did: from pathlib import Path home = str(Path.home())

in main.py, as described here: https://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python

and it worked