rfl:从 lean 开始的异世界生活(2)——安装 lean copilot

按照 github repo 的安装方法:

先在 lakefile.lean 中加入 Lean Copilot 作为 dependency,对于 lakefile.toml,可自行查阅 github 上的 readme.

package «my-package» {
  moreLinkArgs := #[
    "-L./.lake/packages/LeanCopilot/.lake/build/lib",
    "-lctranslate2"
  ]
}

require LeanCopilot from git "https://github.com/lean-dojo/LeanCopilot.git" @ "v4.21.0"

注意这里 Lean Copilot 的版本和 mathlib 版本最好一样,不然会有一堆莫名报错.

If you are using native Windows, add <path_to_your_project>/.lake/packages/LeanCopilot/.lake/build/lib to your Path variable in Advanced System Settings > Environment Variables... > System variables.

然后 lake update LeanCopilot.如果正好需要更新 lean 工具链,可以使用 SJTU 提供的 glean

到这里应该一切正常了.但是接下来按官方说明,

lake exe LeanCopilot/download

就会喜提报错:

✖ [3473/3580] Building LeanCopilot/libctranslate2
info: Cloning CTranslate2 from https://github.com/OpenNMT/CTranslate2
info: Configuring CTranslate2 with `cmake -DOPENMP_RUNTIME=NONE -DWITH_MKL=OFF -DWITH_ACCELERATE=OFF -DWITH_OPENBLAS=ON -DOPENBLAS_INCLUDE_DIR=../../OpenBLAS -DOPENBLAS_LIBRARY=../../OpenBLAS/libopenblas.so ..`
error: Failed to run cmake

看了一眼我 cmake 版本也不低啊?那怎么回事呢?

尝试切进目录手动执行 cmake 命令:

cd .lake/packages/LeanCopilot/.lake/build/CTranslate2/build
cmake -DOPENMP_RUNTIME=NONE -DWITH_MKL=OFF -DWITH_ACCELERATE=OFF -DWITH_OPENBLAS=ON -DOPENBLAS_INCLUDE_DIR=../../OpenBLAS -DOPENBLAS_LIBRARY=../../OpenBLAS/libopenblas.so ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax          
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- Build spdlog: 1.10.0
-- Build type: Release
CMake Error at third_party/cpu_features/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 has been removed from CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.

  Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.


-- Configuring incomplete, errors occurred! 

原来是 cmake 版本太高了.在 .lake/packages/LeanCopilot/.lake/build/CTranslate2/ 目录里,手动修改一下 ../third_party/cpu_features/CMakeLists.txt,把 cmake_minimum_required 调高就行了.

然后重新跑,报了一屏幕的 c++ 编译错误.修改 ../third_party/cxxopts/include/cxxopts.hpp,加入 #include <cstdint>

跑起来了,但是 huggingface 访问缓慢,于是在 hf-mirror.com 镜像站上把 github readme 里提到的四个 repo clone 进 ~/.cache/lean_copilot/models/huggingface.co/kaiyuy/ct2-byt5-small 里.

试一下 lake build,没有问题.在代码里 import LeanCopilot 即可使用.

使用体验

由于一些神秘原因,只能用 CPU 跑.

烟瘾丁真,鉴定为:纯纯的肺雾.

posted @ 2025-08-04 17:09  383494  阅读(17)  评论(0)    收藏  举报