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

Error running ltchiptool gui under macOS 13.6.1 #14

Open
cohm opened this issue Nov 12, 2023 · 12 comments
Open

Error running ltchiptool gui under macOS 13.6.1 #14

cohm opened this issue Nov 12, 2023 · 12 comments

Comments

@cohm
Copy link

cohm commented Nov 12, 2023

I'm trying to use ltchiptool as part of following this guide but I'm having trouble getting ltchiptool to run on my Mac (I see it's "untested" according to the docs, so perhaps this is useful feedback). FWIW, I'm on macOS 13.6.1 (22G313), I have python 3.11.6 via homebrew, and I installed wxPython and ltchiptool, but got this error when starting the gui. I tried both 4.2.3 as used in the guide, and then the current latest version (4.7.0), and got two different errors. The full output is below.

Any ideas how to get the GUI to work under macOS?

Thanks a lot in advance!

OhmBookPro13:~/Downloads > pip3 install wxpython
Collecting wxpython
  Using cached wxPython-4.2.1-cp311-cp311-macosx_10_10_universal2.whl.metadata (2.9 kB)
Requirement already satisfied: pillow in /usr/local/lib/python3.11/site-packages (from wxpython) (10.1.0)
Requirement already satisfied: six in /usr/local/lib/python3.11/site-packages (from wxpython) (1.16.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.11/site-packages (from wxpython) (1.26.1)
Using cached wxPython-4.2.1-cp311-cp311-macosx_10_10_universal2.whl (31.5 MB)
Installing collected packages: wxpython
Successfully installed wxpython-4.2.1
OhmBookPro13:~/Downloads > pip3 install ltchiptool==4.2.3
Collecting ltchiptool==4.2.3
  Using cached ltchiptool-4.2.3-py3-none-any.whl.metadata (3.8 kB)
Requirement already satisfied: bitstruct<9.0.0,>=8.17.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (8.19.0)
Requirement already satisfied: bk7231tools<2.0.0,>=1.3.6 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (1.4.0)
Requirement already satisfied: click<9.0.0,>=8.1.3 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (8.1.7)
Requirement already satisfied: colorama<0.5.0,>=0.4.5 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (0.4.6)
Requirement already satisfied: hexdump<4.0,>=3.3 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (3.3)
Requirement already satisfied: importlib-metadata<5.0.0,>=4.12.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (4.13.0)
Requirement already satisfied: prettytable<4.0.0,>=3.3.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (3.9.0)
Requirement already satisfied: py-datastruct<0.5.0,>=0.4.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (0.4.0)
Requirement already satisfied: pycryptodomex<4.0.0,>=3.15.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (3.19.0)
Requirement already satisfied: semantic-version<3.0.0,>=2.10.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (2.10.0)
Requirement already satisfied: xmodem<0.5.0,>=0.4.6 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool==4.2.3) (0.4.7)
Requirement already satisfied: pyserial<4.0,>=3.5 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from bk7231tools<2.0.0,>=1.3.6->ltchiptool==4.2.3) (3.5)
Requirement already satisfied: zipp>=0.5 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from importlib-metadata<5.0.0,>=4.12.0->ltchiptool==4.2.3) (3.17.0)
Requirement already satisfied: wcwidth in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from prettytable<4.0.0,>=3.3.0->ltchiptool==4.2.3) (0.2.9)
Using cached ltchiptool-4.2.3-py3-none-any.whl (159 kB)
Installing collected packages: ltchiptool
Successfully installed ltchiptool-4.2.3
OhmBookPro13:~/Downloads > python3 -m ltchiptool gui
22:34:42: Debug: Adding duplicate image handler for 'Windows bitmap file'
22:34:42: Debug: Adding duplicate animation handler for '1' type
22:34:42: Debug: Adding duplicate animation handler for '2' type
Fatal Python error: PyGILState_Release: thread state 0x105888d28 must be current when releasing
Python runtime state: initialized

Current thread 0x00007ff84f543700 (most recent call first):
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/colors.py", line 128 in apply
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/panels/log.py", line 206 in OnPaletteChanged
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/main.py", line 324 in palette
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/main.py", line 187 in SetSettings
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/main.py", line 242 in OnShow
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/util/../../ltchiptool/gui/__main__.py", line 30 in gui_entrypoint
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/util/../../ltchiptool/gui/__main__.py", line 48 in cli
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 783 in invoke
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 1434 in invoke
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 1688 in invoke
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 1078 in main
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 1157 in __call__
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/__main__.py", line 112 in cli
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/__main__.py", line 119 in <module>
  File "<frozen runpy>", line 88 in _run_code
  File "<frozen runpy>", line 198 in _run_module_as_main

Extension modules: wx._core, wx._adv, wx._xml, wx._xrc, wx._dataview (total: 5)
Abort trap: 6
OhmBookPro13:~/Downloads > python3 --version
Python 3.11.6
OhmBookPro13:~/Downloads > pip3 uninstall ltchiptool       
Found existing installation: ltchiptool 4.2.3
Uninstalling ltchiptool-4.2.3:
  Would remove:
    /usr/local/bin/ltchiptool
    /usr/local/lib/python3.11/site-packages/ltchiptool-4.2.3.dist-info/*
    /usr/local/lib/python3.11/site-packages/ltchiptool/*
    /usr/local/lib/python3.11/site-packages/ltctplugin/base/*
    /usr/local/lib/python3.11/site-packages/uf2tool/*
Proceed (Y/n)? Y
  Successfully uninstalled ltchiptool-4.2.3
OhmBookPro13:~/Downloads > pip3 install ltchiptool       
Collecting ltchiptool
  Using cached ltchiptool-4.7.0-py3-none-any.whl.metadata (3.8 kB)
Requirement already satisfied: bitstruct<9.0.0,>=8.1.1 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (8.19.0)
Requirement already satisfied: bk7231tools<2.0.0,>=1.3.6 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (1.4.0)
Requirement already satisfied: click<9.0.0,>=8.1.3 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (8.1.7)
Requirement already satisfied: colorama<0.5.0,>=0.4.5 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (0.4.6)
Requirement already satisfied: hexdump<4.0,>=3.3 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (3.3)
Requirement already satisfied: importlib-metadata in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (4.13.0)
Requirement already satisfied: prettytable<4.0.0,>=3.3.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (3.9.0)
Requirement already satisfied: py-datastruct<0.5.0,>=0.4.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (0.4.0)
Requirement already satisfied: pycryptodomex<4.0.0,>=3.9.9 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (3.19.0)
Requirement already satisfied: semantic-version<3.0.0,>=2.10.0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (2.10.0)
Requirement already satisfied: xmodem<0.5.0,>=0.4.6 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (0.4.7)
Requirement already satisfied: zeroconf<1,>=0 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from ltchiptool) (0.123.0)
Requirement already satisfied: pyserial<4.0,>=3.5 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from bk7231tools<2.0.0,>=1.3.6->ltchiptool) (3.5)
Requirement already satisfied: wcwidth in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from prettytable<4.0.0,>=3.3.0->ltchiptool) (0.2.9)
Requirement already satisfied: ifaddr>=0.1.7 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from zeroconf<1,>=0->ltchiptool) (0.2.0)
Requirement already satisfied: zipp>=0.5 in /Users/cohm/Library/Python/3.11/lib/python/site-packages (from importlib-metadata->ltchiptool) (3.17.0)
Using cached ltchiptool-4.7.0-py3-none-any.whl (163 kB)
Installing collected packages: ltchiptool
Successfully installed ltchiptool-4.7.0
OhmBookPro13:~/Downloads > python3 -m ltchiptool gui
22:41:08: Debug: Adding duplicate image handler for 'Windows bitmap file'
22:41:08: Debug: Adding duplicate animation handler for '1' type
22:41:08: Debug: Adding duplicate animation handler for '2' type
Fatal Python error: PyGILState_Release: thread state 0x10617dd28 must be current when releasing
Python runtime state: initialized

Thread 0x0000700004db5000 (most recent call first):
  File "/usr/local/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/selectors.py", line 566 in select
  File "/usr/local/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 1884 in _run_once
  File "/usr/local/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 607 in run_forever
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/zeroconf/_core.py", line 223 in _run_loop
  File "/usr/local/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 982 in run
  File "/usr/local/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1045 in _bootstrap_inner
  File "/usr/local/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1002 in _bootstrap

Current thread 0x00007ff84f543700 (most recent call first):
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/colors.py", line 128 in apply
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/panels/log.py", line 247 in OnPaletteChanged
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/main.py", line 334 in palette
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/main.py", line 194 in SetSettings
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/gui/main.py", line 252 in OnShow
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/util/../../ltchiptool/gui/__main__.py", line 32 in gui_entrypoint
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/util/../../ltchiptool/gui/__main__.py", line 50 in cli
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 783 in invoke
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 1434 in invoke
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 1688 in invoke
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 1078 in main
  File "/Users/cohm/Library/Python/3.11/lib/python/site-packages/click/core.py", line 1157 in __call__
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/__main__.py", line 122 in cli
  File "/usr/local/lib/python3.11/site-packages/ltchiptool/__main__.py", line 129 in <module>
  File "<frozen runpy>", line 88 in _run_code
  File "<frozen runpy>", line 198 in _run_module_as_main

Extension modules: wx._core, wx._adv, wx._xml, wx._xrc, zeroconf._utils.time, zeroconf._dns, zeroconf._protocol.outgoing, zeroconf._protocol.incoming, zeroconf._cache, zeroconf._record_update, zeroconf._updates, zeroconf._handlers.record_manager, zeroconf._services, zeroconf._services.info, zeroconf._services.registry, zeroconf._listener, zeroconf._handlers.answers, zeroconf._handlers.multicast_outgoing_queue, zeroconf._history, zeroconf._handlers.query_handler, zeroconf._services.browser, wx._dataview (total: 22)
Abort trap: 6
OhmBookPro13:~/Downloads > /usr/local/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 3 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
@kuba2k2
Copy link
Member

kuba2k2 commented Nov 13, 2023

It seems that MacOS doesn't support setting text styles. Try commenting out this line to see if a different error shows up:
https://github.com/libretiny-eu/ltchiptool/blob/master/ltchiptool/gui/colors.py#L128

@cohm
Copy link
Author

cohm commented Nov 13, 2023

Thanks - commenting out that line makes it work, and the GUI now pops up without any error messages! If it's helpful I'm happy to provide a fix for this for mac users (just protecting the problematic line behind something like platform.system() != 'Darwin').

I have a follow-up question: I installed the UPK2ESPHome plugin (through putting in this string and hitting "Download plugins..." button), and this works:
Screenshot 2023-11-13 at 22 23 10
However, when I try to use it to grab the config for my device flashed with ESPHome-Kickstart, the program exits and I get a cryptic error message:

OhmBookPro13:~/Downloads > python3 -m ltchiptool gui
22:28:13: Debug: Adding duplicate image handler for 'Windows bitmap file'
22:28:13: Debug: Adding duplicate animation handler for '1' type
22:28:13: Debug: Adding duplicate animation handler for '2' type
I: Loaded settings from /Users/cohm/Library/Application Support/ltchiptool/gui.json
I: Found new device: cu.BLTH - n/a
I: Found new device: cu.Bluetooth-Incoming-Port - n/a
Illegal instruction: 4
OhmBookPro13:~/Downloads > /usr/local/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 3 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

The web interface for the device seems to work fine:
Screenshot 2023-11-13 at 22 26 20

If this question is better asked in the upk2esphome repo I'm happy to ask there, of course!

Many thanks for your quick reply btw, @kuba2k2!

PS. I did upload generic-bk7231n-qfn32-tuya to the device, but it's clearly not working, so this is why I want to grab the config through UPK2ESPHome. I guess this can be the cause of the problem, but I still have the web interface to the device where I can upload new firmware, so I was hoping the grabbing would still work..

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 13, 2023

I don't know what Illegal instruction: 4 might mean. However, the web interface is NOT esphome-kickstart, which upk2esphome requires. Flash kickstart to the device and try upk2esphome again - maybe it will work if it's able to connect (it should even detect the Kickstart device's IP automatically).

I'm glad it works, I haven't seen it run on MacOS before but honestly it looks fantastic.

I wonder why the text style crashed the app - you can clearly see text style being applied in the log window (green text).

It's also good to know that downloading plugins actually works. On Linux, for example, switching to the Plugins tab crashes the program right away... One can obviously install plugins with pip. Oh and the "Download plugins..." button is actually there to search for plugins - it will display a list of all available 😄

@cohm
Copy link
Author

cohm commented Nov 13, 2023

Wow - thanks for the lightning reply!

Ok, so my failed attempt is likely the reason, good to know. Should I just grab the .bin from here and upload via the web interface? https://github.com/tuya-cloudcutter/tuya-cloudcutter/blob/main/custom-firmware/ESPHome-Kickstart-v23.08.29_bk7231n_app.ota.ug.bin (I know my device has bk7231n)

I'm quite new to this, and only tried to upload a .uf2 file made by ESPhome - I don't want to brick the device by uploading a bad file..

About the text style, no idea - I did comment out that line (this was what allowed the gui to work on my mac), so I guess it's somehow not needed?

Interesting that the "Download plugins..." button should list available plugins - that's what I expected too, but I played around a bit since that actually didn't work for me. I got an error message saying "request doesn't exist" or similar. Now when I tried again to reproduce it and provide a screen dump, it actually worked :)

Screenshot 2023-11-13 at 22 53 34

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 13, 2023

That's the cool part here - you can't brick the device by uploading the wrong file, unless you intend to do so by creating a bad file (or the firmware has problems booting up). For LibreTiny, you only need UF2 files - they work nearly everywhere.

That line you commented was used for changing style of the log window (if you change the color scheme in menu). The line responsible for setting colors in the first place is still somewhere there.

Oh so I forgot to include "requests" in dependencies.. good to know, let's keep this issue open. It works now because installing upk2esphome probably added the missing package.

@cohm
Copy link
Author

cohm commented Nov 13, 2023

Great to hear about the brick protection! Sorry if I'm slow, but where do I get the kickstart uf2 file I should upload to see if I can get the grabbing via upk2esphome to work?

What you write about the text style and missing requests dependency makes perfect sense - happy to try to navigate through this on a Mac and hopefully provide some helpful feedback in the process :)

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 13, 2023

Get the kickstart file from esphome-kickstart repository. It's under the libretiny-eu organization on GitHub.

@cohm
Copy link
Author

cohm commented Nov 13, 2023

Ok, progress - I grabbed the uf2 file (for anyone as inexperienced as me landing here, it can be found in the assets of the release, but not in the repo itself where I first poked around). This uploaded just fine to the device via the web interface, and allowed the grabbing to start at least, even if it failed and killed the gui before it finished:
Screenshot 2023-11-13 at 23 17 57
No obvious error in the web interface log there, but in the terminal:

OhmBookPro13:~/Downloads > python3 -m ltchiptool gui
23:22:03: Debug: Adding duplicate image handler for 'Windows bitmap file'
23:22:03: Debug: Adding duplicate animation handler for '1' type
23:22:03: Debug: Adding duplicate animation handler for '2' type
I: Loaded settings from /Users/cohm/Library/Application Support/ltchiptool/gui.json
I: Found new device: cu.BLTH - n/a
I: Found new device: cu.Bluetooth-Incoming-Port - n/a
Abort trap: 6

In case it's helpful, these were the last lines in the web interface log:

23:22:20	[D]	[hub_api:037]	
Reading flash: offset=1fd000, length=2048
23:22:20	[D]	[hub_api:037]	
Reading flash: offset=1fd800, length=2048
23:22:20	[D]	[hub_api:037]	
Reading flash: offset=1fe000, length=2048
23:22:20	[D]	[hub_api:037]	
Reading flash: offset=1fe800, length=2048
23:22:20	[D]	[hub_api:037]	
Reading flash: offset=1ff000, length=2048
23:22:20	[D]	[hub_api:037]	
Reading flash: offset=1ff800, length=2048

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 13, 2023

It seems to have finished reading at least. It's probably related to the way bk7231tools currently extracts that data - it uses some weird go-to magic. I'm currently in the middle of rewriting that.

@cohm
Copy link
Author

cohm commented Nov 13, 2023

Ok, I guess I'm stuck here for now then, but I'm not in a rush in any way. Thanks again for the incredible support and fast replies so far!

@cohm
Copy link
Author

cohm commented Jan 3, 2024

FWIW, I just tried this again after updating to ltchiptool 4.10.1, but I still get the same error as in my last message above. I guess I should look for a new release of bk7231tools before I should expect the suspected issue above to be resolved? I currently have 1.5.4.

Happy help test something if that's useful!

@jon-daemon
Copy link

I also get this on Mac OS 11.7

/usr/local/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 4 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

It happened when I connected CEN to GND so probably when the chip was seen. Also it happened when I clicked Grab from ESPHome-Kickstart on another chip with ESPHome-Kickstart firmware flashed.

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

3 participants