想尝试python使用llama-cpp的功能,在windows下安装llama-cpp-python时,会报错。
PS C:\Users\xxxx> pip install llama-cpp-python
...
...
Building wheels for collected packages: llama-cpp-python
Running command Building wheel for llama-cpp-python (pyproject.toml)
*** scikit-build-core 0.9.9 using CMake 3.30.1 (wheel)
*** Configuring CMake...
2024-07-31 15:38:35,991 - scikit_build_core - WARNING - Can't find a Python library, got libdir=None, ldlibrary=None, multiarch=None, masd=None
loading initial cache file C:\Users\xxxx\AppData\Local\Temp\tmp95k50mhv\build\CMakeInit.txt
-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:3 (project):
Running
'nmake' '-?'
failed with:
no such file or directory
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
*** CMake configuration failed
error: subprocess-exited-with-error
× Building wheel for llama-cpp-python (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> See above for output.
...
...
错误信息提示是找不到nmake。网上查找了一下,nmake是VisualStudio自带的开发工具,但是为了避免安装庞大的VS,我们只需要安装Vs build tools,记得要选中“使用C++的桌面开发”。
安装成功后,可以看到系统里已经有nmake.exe了,路径也无需配置。
再次使用pip安装llama-cpp-python,成功编译。
PS C:\Users\xxxx> pip install llama-cpp-python
...
Successfully built llama-cpp-python
WARNING: Ignoring invalid distribution ~mzqr (D:\Python312\Lib\site-packages)
Installing collected packages: MarkupSafe, diskcache, jinja2, llama-cpp-python
WARNING: Ignoring invalid distribution ~mzqr (D:\Python312\Lib\site-packages)
Successfully installed MarkupSafe-2.1.5 diskcache-5.6.3 jinja2-3.1.4 llama-cpp-python-0.2.84