VS Code中Jupyter缺失带CUBLAS编译的llama-cpp-python包问题
解决Jupyter中找不到编译的llama-cpp-python模块问题
直接在Jupyter环境内重新编译安装
既然终端环境能正常识别该包,但Jupyter中无法检测到,直接在Jupyter里重新执行带CUBLAS的编译安装流程:
- 先卸载可能残留的无效版本:
!pip uninstall -y llama-cpp-python
- 根据系统设置CUBLAS编译参数并重新安装:
- Linux/macOS:
!CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --force-reinstall --no-cache-dir- Windows:
!set CMAKE_ARGS="-DLLAMA_CUBLAS=on" && pip install llama-cpp-python --force-reinstall --no-cache-dir
验证安装与导入
安装完成后,先确认包已出现在Jupyter的包列表中:
%pip list | grep llama-cpp-python
再测试模块导入:
from llama_cpp import Llama
额外排查调整
- 确认VS Code的Jupyter内核与终端环境一致:查看VS Code左下角状态栏的Python环境选择器,切换到终端使用的同一个虚拟/全局环境
- 若使用conda环境,可重新绑定Jupyter内核:
conda activate 你的环境名 python -m ipykernel install --user --name 你的环境名 --display-name "Python (你的环境名)"
之后在Jupyter中切换到这个新创建的内核再测试
内容的提问来源于stack exchange,提问作者pbk
相关产品推荐
相关产品推荐

