使用 katago 复盘围棋

沥川 bio photo By 沥川

背景

触发 【围棋】9路围棋的一种错误开局和几个常见布局 使用 katago 进行围棋复盘分析, 非常好用

计划

在 MacPro 上配置 katago, 进行围棋复盘及分析

方案

  • 安装 katago
  • 安装 Katrain 运行命令katrain 即可
  • 对弈使用 katrain, 可以调整 ai 级别
  • 复盘使用 lizzie

流程

  • 在 GitHub 上找到 KataGo 仓库

  • 发现需要使用 Katrain 的 GUI

  • 安装 brew install katago 报错

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

Error: No available formula with the name "katago"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
  • 尝试提示信息 git -C "$(brew --repo homebrew/core)" fetch --unshallow

  • 每次停在 Updating Homebrew... 时间非常久

  • 更新了 homebrew 以后, 可以运行 brew install katago 并没有报错, 结果如下

icu4c is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).

If you need to have icu4c first in your PATH run:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.zshrc

For compilers to find icu4c you may need to set:
  export LDFLAGS="-L/usr/local/opt/icu4c/lib"
  export CPPFLAGS="-I/usr/local/opt/icu4c/include"

For pkg-config to find icu4c you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"
  • 安装 install katrain

过程中报错

ERROR: Exception:
Traceback (most recent call last):
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 437, in _error_catcher
    yield
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/http/client.py", line 449, in read
    n = self.readinto(b)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/http/client.py", line 493, in readinto
    n = self.fp.readinto(b)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/ssl.py", line 1002, in recv_into
    return self.read(nbytes, buffer)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/ssl.py", line 865, in read
    return self._sslobj.read(len, buffer)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/ssl.py", line 625, in read
    v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
    status = self.run(options, args)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
    return func(self, options, args)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 325, in run
    reqs, check_supported_wheels=not options.target_dir
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 183, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 388, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 340, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 469, in prepare_linked_requirement
    hashes=self._get_linked_req_hashes(req)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 259, in unpack_url
    hashes=hashes,
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 130, in get_http_url
    link, downloader, temp_dir.path, hashes
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 282, in _download_http_url
    for chunk in download.chunks:
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/cli/progress_bars.py", line 168, in iter
    for x in it:
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_internal/network/utils.py", line 88, in response_chunks
    decode_content=False,
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 576, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 541, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/contextlib.py", line 100, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/hugo/.pyenv/versions/3.6.1/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 442, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
  • 查找资料, 发现是由于国内联网原因, pip 下载超时. 延长时间限制即可

pip install --default-timeout=1000 --no-cache-dir -r requirements.txt

出现问题

ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'   

pip freeze > requirements.txt

  • 这个里面的解决方法:pip freeze > requirements.txt 只是将当前的虚拟环境中的依赖包以版本号生成至文件中,生成的requirement.txt文件并不是你的工程所需要的依赖包的要求信息,这个方法不可行。 这个方法只是为了再次创建虚拟环境时安装依赖的一个技巧。

  • 然后再输入 pip install --default-timeout=1000 --no-cache-dir -r requirements.txt 没有报错

  • 再次安装 install katrain 仍然报错, 并没有解决问题

  • 查看资料 解决pip超时的问题 , 进行手动换源

pip install katrain -i https://pypi.tuna.tsinghua.edu.cn/simple/ 解决问题, 速度非常的快.

Ok I feel really dumb. I was missing one of the very obvious steps in the readme file. You need to add the Leela Zero to the Lizzie directory. On a mac, you can install Leela Zero using Homebrew:

brew install leela-zero

Then copy the file /usr/local/Cellar/leela-zero/0.17/bin/leelaz into the Lizzie main directory. Worked for me.
  • 需要先安装 brew install leela-zero

  • 然后要将 leela-zero 放到 lezzie 文件夹下

  • Homebrew 安装地址, 可以使用 brew list 来查询路径, 例如 brew list katago

  • 执行 brew install 命令长时间卡在 Updating Homebrew 的解决方法

  • 方法 1:按住 control + c 取消本次更新操作

  • 参考 readme 安装 leelazero 后正式启动

  • 运行过程中出现 java.io.IOException: Stream closed 报错

  • 尝试安装 Sabaki v0.51.1

  • 配置引擎失败, 还是使用 katrain 好了, 结束.

  • homebrew 更新软件 brew upgrade 软件名

参考

Changelog

  • 2020-09-04 lichuan init.