Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Windows compatibility #31

Closed
AnderssonPeter opened this issue Mar 8, 2017 · 12 comments
Closed

Windows compatibility #31

AnderssonPeter opened this issue Mar 8, 2017 · 12 comments

Comments

@AnderssonPeter
Copy link

AnderssonPeter commented Mar 8, 2017

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
Copy link
Owner

Ape commented Mar 9, 2017

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
Copy link
Author

AnderssonPeter commented Mar 9, 2017

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
Copy link
Owner

Ape commented Mar 10, 2017

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
Copy link
Author

AnderssonPeter commented Mar 10, 2017

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.

  • "USERPROFILE" Root directory of the user profile
  • "APPDATA" Location to store application data that will be synchronized between computers if same user logs in (requires a domain for the synchronization to take place)
  • "LOCALAPPDATA" Same as above without synchronization.
  • "ProgramData" Here you can store data that is shared between all users.

@Ape
Copy link
Owner

Ape commented Mar 10, 2017

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?

@Ape Ape changed the title ModuleNotFoundError: No module named '_curses' Windows compatibility Mar 10, 2017
@AnderssonPeter
Copy link
Author

AnderssonPeter commented Mar 10, 2017

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
Copy link
Author

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
Copy link
Owner

Ape commented Mar 11, 2017

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

@AnderssonPeter
Copy link
Author

AnderssonPeter commented Mar 11, 2017

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
Copy link
Owner

Ape commented Mar 11, 2017

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

@AnderssonPeter
Copy link
Author

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
Copy link

Bakipl commented Dec 14, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants