Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python under Win10 #145

Closed
itispip opened this issue Jan 14, 2021 · 8 comments
Closed

Support Python under Win10 #145

itispip opened this issue Jan 14, 2021 · 8 comments

Comments

@itispip
Copy link

itispip commented Jan 14, 2021

OS: Win10
Python: 3.8.6

Error Msg below due to Windows doesn't support nl_langinfo:

Traceback (most recent call last):
File "d:\homeassistant\lib\site-packages\homeassistant\config_entries.py", line 236, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "C:\Users\Alex\AppData\Roaming.homeassistant\custom_components\pyscript_init_.py", line 123, in async_setup_entry
TrigTime.init(hass)
File "C:\Users\Alex\AppData\Roaming.homeassistant\custom_components\pyscript\trigger.py", line 142, in init
cls.dow2int[locale.nl_langinfo(getattr(locale, f"ABDAY_{i + 1}")).lower()] = i
AttributeError: module 'locale' has no attribute 'nl_langinfo'

@craigbarratt
Copy link
Member

As you discovered, pyscript hasn't been tested on Windows. That particular code gets language (locale) specific strings for days of the week. Is there some other way to get that in Python on Windows?

You could temporarily hardcode it in English to at least see whether there are subsequent Windows-related issues.

@itispip
Copy link
Author

itispip commented Jan 15, 2021

Hardcode below. No error. But if user's Windows language is not English(US) will it be a problem?

    cls.dow2int['sun'] = 0
    cls.dow2int['sunday'] = 0
    cls.dow2int['mon'] = 1
    cls.dow2int['monday'] = 1
    cls.dow2int['tue'] = 2
    cls.dow2int['tuesday'] = 2
    cls.dow2int['wed'] = 3
    cls.dow2int['wednesday'] = 3
    cls.dow2int['thu'] = 4
    cls.dow2int['thursday'] = 4
    cls.dow2int['fri'] = 5
    cls.dow2int['friday'] = 5
    cls.dow2int['sat'] = 6
    cls.dow2int['saturday'] = 6

@itispip
Copy link
Author

itispip commented Jan 15, 2021

Another error is pyscript cannot handle multi-bytes character?

Logger: custom_components.pyscript
Source: C:\Users\Alex\AppData\Roaming.homeassistant\custom_components\pyscript_init_.py:348
Integration: Pyscript Python scripting (documentation, issues)

load_scripts: skipping C:\Users\Alex\AppData\Roaming.homeassistant\pyscript\example.py due to exception 'gbk' codec can't decode byte 0xaf in position 199: illegal multibyte sequence

@craigbarratt
Copy link
Member

I guess we could hardcode the days-of-week on Windows, but, yes, it would only be in English.

For the 2nd error, Python should be expecting unicode with utf8 encoding. Do you know the encoding of your files on Windows? What are the hex byte values around byte #199?

@itispip
Copy link
Author

itispip commented Jan 15, 2021

It's not a file encoding issue. The py file encoding is utf8 no BOM.

This error happen when I use the example code in tutorial to call tts.google_translate_say service. If I pass a multi-byte string to the "message" parameter of google_translate_say, no matter Japanese, Chinese, Korean or Thai, the example.py script cannot be loaded.

@service
def hello_world(action=None, id=None):
"""hello_world example using pyscript."""
log.info(f"hello world: got action {action} id {id}")
tts.google_translate_say(entity_id='media_player.vlc', message='นี่คือการทดสอบ')

Same file but pass an English string to message is fine.

@craigbarratt
Copy link
Member

Can you try something simpler, eg just do this:

log.info('นี่คือการทดสอบ')

That works for me on MacOSX.

@itispip
Copy link
Author

itispip commented Jan 16, 2021

Can you try something simpler, eg just do this:

log.info('นี่คือการทดสอบ')

That works for me on MacOSX.

No, still the same.

I have tried to change Windows Display language to English, but the error is the same, so it's not related with system locale.

@craigbarratt
Copy link
Member

It looks like on windows open() doesn't default to utf-8 encoding. I added encoding="utf-8" to each open() call. This should fix the issue.

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

No branches or pull requests

2 participants