sanderland / katrain

Improve your Baduk skills by training with KataGo!
Other
1.63k stars 227 forks source link

Combined issues for running Katrain on 2020 Mac M1 architectures #331

Closed kentdorsey closed 2 years ago

kentdorsey commented 3 years ago

I worked through several dependency issues during installation, including sdl2* and libavcodec (resolved latter via brew install ffmpeg). However, at runtime, the following error appears:

% katrain -d
[INFO   ] [Logger      ] Record log in /Users/REDACTED/.kivy/logs/kivy_21-01-20_24.txt
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "/opt/homebrew/lib/python3.9/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.9.1 (default, Jan  8 2021, 12:11:08) 
[Clang 12.0.0 (clang-1200.0.32.28)]
[INFO   ] [Python      ] Interpreter at "/opt/homebrew/opt/python@3.9/bin/python3.9"
[ERROR  ] [Clock       ] Unable to import kivy._clock. Have you perhaps forgotten to compile kivy? Kivy contains Cython code which needs to be compiled. A missing kivy._clock often indicates the Cython code has not been compiled. Please follow the installation instructions and make sure to compile Kivy
 Traceback (most recent call last):
   File "/opt/homebrew/bin/katrain", line 5, in <module>
     from katrain.__main__ import run_app
   File "/opt/homebrew/lib/python3.9/site-packages/katrain/__main__.py", line 48, in <module>
     from kivy.base import ExceptionHandler, ExceptionManager
   File "/opt/homebrew/lib/python3.9/site-packages/kivy/base.py", line 28, in <module>
     from kivy.clock import Clock
   File "/opt/homebrew/lib/python3.9/site-packages/kivy/clock.py", line 466, in <module>
     from kivy._clock import CyClockBase, ClockEvent, FreeClockEvent, \
 ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/kivy/_clock.cpython-39-darwin.so, 2): no suitable image found.  Did find:
    /opt/homebrew/lib/python3.9/site-packages/kivy/_clock.cpython-39-darwin.so: mach-o, but wrong architecture
    /opt/homebrew/lib/python3.9/site-packages/kivy/_clock.cpython-39-darwin.so: mach-o, but wrong architecture
vividfog commented 3 years ago

Here's a potentially useful breadcrumb when running under Rosetta 2:

>>> platform.version()
'Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101'

>>> platform.uname()
('Darwin', 'm1.local', '20.3.0', 'Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101', 'x86_64', 'i386')
sanderland commented 3 years ago

and what are they under non-rosetta python?

vividfog commented 3 years ago

Here you go:

> python3
Python 3.9.1 (default, Jan  8 2021, 12:11:08)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.machine()
'arm64'
>>> platform.version()
'Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101'
>>> platform.uname()
uname_result(system='Darwin', node='m1.local', release='20.3.0', version='Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101', machine='arm64')
sanderland commented 3 years ago

So 'arm64' in platform.version().lower() seems safe, thanks!

sanderland commented 3 years ago

https://github.com/sanderland/katrain/runs/1783842496

vividfog commented 3 years ago

This is progress, platform recognition works.

The problem is that .zshrc's PATH settings don't get read by the macOS GUI layers and the $PATH will not be set for most users. I don't know what extra @kentdorsey did to make it visible for the .app.

If your goal is a "just run it" type installation, I would suggest that there would be a manual test, whether /opt/homebrew/bin/katago exists, if you support this homebrew route to this extent to begin with. That's the place where it will go for almost every arm64 user of homebrew. Unless they consciously install homebrew elsewhere by hand.

PATH not available
vividfog commented 3 years ago

On the previous point. Did some googling. Setting a truly global $PATH for macOS is possible, but it's complicated enough that not many people out of 100 will have it set, even out of 100 Homebrew users. A true drop-in installation would have to use some other method to find the katago binary. The good news is that the path is relatively predictable.

sanderland commented 3 years ago

https://github.com/sanderland/katrain/pull/344/checks?check_run_id=1784584592

vividfog commented 3 years ago

👍

great success

katrain.log

vividfog commented 3 years ago

Ok, so now it works as expected. There's one more optimization, but I don't know if github's process has a way around it: The app isn't yet signed. As a result, it can't be opened just with a double click. One has to right-click and select Open from the context menu.

Upon the first launch it will show this:

first launch

Clicking cancel and opening it via the context menu again:

second launch

That's Apple's way of trying to discourage users from opening unsigned apps. It's working as designed.

This doesn't really bother me, but just so you know. Once the app has been open once, then those dialogs go away. The behavior will be the same for Intel Macs too, on Big Sur.

sanderland commented 3 years ago

Yeah that's hard to avoid, i understand dev keys are sold on subscription and need a mac to apply as well. Typical apple.

vividfog commented 3 years ago

It's not a biggie, lots of indie software works this way. Just make a mention of it in the install info. Good job, I can't think of anything else. We're done for now, as far as I can see. Maybe @kentdorsey could confirm?

[✓] M1 support

kentdorsey commented 3 years ago

I believe that I set the path manually in the full screen native initially. Does the app share the same configuration files? It is in my path but the homebrew bin path is set in .zprofile not .zshrc.

vividfog commented 3 years ago

Ok, the latest .app has a feature that tries to find the arm64 katago provided by homebrew, even if not pointed at one.

If you had previously set the path to it manually, then surely it was found and $PATH info was never needed. And there's a good reason to believe that had you not set it manually, it wouldn't have been found, because .zprofile would not have been applied. Global $PATH requires extra configuration.

The conf files are shared as far as I can tell, in ~/katrain folder.

The test case is this:

  1. Download the latest bundle
  2. Run it from Finder, make sure that katago path is empty in Settings
  3. Restart it; see if it still finds /opt/homebrew/bin/katago (= Analysis works)

This will capture the logs but may also apply $PATH locally from the terminal environment, so not sure if it's a great test: /Applications/KaTrain.app/Contents/Resources/script &> katrain.log

peepo commented 3 years ago

9x9?

has anyone, or could anyone please run 9x9 and comment? ie does it display? any issues?

also: I'm considering purchasing M1, is there a current maintained install wiki?

tx

studying 9x9 ~4dan, progress is slow to absent.

I created_ the original Go game heatmap GUI & more at peepo.com

peepo commented 3 years ago

on GPU: https://github.com/AsahiLinux/gpu

peepo commented 3 years ago

is there a wiki or other writeup or howto for M1 architecture? I currently seem likely to purchase M1 have plenty of bash experience, not so much OSX so could try either single click install, or a complete instruction set. but where is it?

tx

sanderland commented 3 years ago

Can any mac user confirm/deny #414 ?

monsterkodi commented 2 years ago

hello, i would love to get this to work on my new mac book air. but so far, i couldn't figure it out. i tried various things mentioned in this thread, but the application just won't start up. any hints how to get this to work nowadays would be appreceated!

berkantaras commented 2 years ago

hello, i would love to get this to work on my new mac book air. but so far, i couldn't figure it out. i tried various things mentioned in this thread, but the application just won't start up. any hints how to get this to work nowadays would be appreceated!

I have the same issue. I found a temporary solution for this. Open terminal and use open -n -a katrain command. A better solution would be appreciated!

tkrajina commented 2 years ago

I tried to run katrain for the last few months with all the workarounds mentioned here and it didn't work.

But the version 1.11 finally works without any issues, I'd suggest you close this issue now.