在Conda环境中安装exllamav2与nmslib时遇多类错误求助
解决方案:Windows 10 Conda环境下exllamav2与nmslib安装及导入问题
一、解决exllamav2的两个导入错误
1. 修复AttributeError: module 'distutils' has no attribute '_msvccompiler'
该错误源于Python 3.10+环境中distutils模块缺失或关联异常,执行以下步骤:
- 通过conda安装完整的distutils包:
conda install -c conda-forge distutils - 若问题未解决,升级setuptools(distutils包含在setuptools组件内):
pip install --upgrade setuptools - 确保编译器环境变量正确:打开Visual Studio x64 Native Tools Command Prompt,激活你的conda环境后再执行后续操作,该终端会自动配置VC++编译器的环境变量,避免编译路径错误。
2. 修复ImportError: DLL load failed while importing exllamav2_ext
此问题多因预编译轮子与本地CUDA/编译器版本不兼容,或依赖DLL缺失,解决步骤:
- 将CUDA路径加入系统PATH:
添加C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin和C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\libnvvp到系统环境变量PATH,重启终端生效。 - 卸载现有exllamav2,从源码编译安装(适配本地环境):
pip uninstall -y exllamav2 git clone https://github.com/turboderp/exllamav2 cd exllamav2 pip install -e . - 若仍提示缺失DLL,检查是否安装cuDNN:下载对应CUDA 11.8版本的cuDNN,解压后将
bin、include、lib目录下的文件分别复制到CUDA Toolkit的对应目录中。
二、成功安装nmslib的步骤
针对Failed to build installable wheels错误,优先使用预编译包规避本地编译失败:
方法1:conda安装(推荐)
conda提供预编译的nmslib包,直接执行:
conda install -c conda-forge nmslib
方法2:本地安装预编译whl文件
找到对应Python 3.10、Windows x64版本的nmslib预编译whl文件,执行:
pip install path/to/nmslib-xxx-cp310-cp310-win_amd64.whl
方法3:源码编译(仅当上述方法失效时)
- 安装编译依赖:
pip install cython numpy cmake - 克隆源码并编译:
git clone https://github.com/nmslib/nmslib cd nmslib/python_bindings pip install -e .
编译前需打开Visual Studio x64 Native Tools Command Prompt,激活conda环境后再操作。
内容的提问来源于stack exchange,提问作者Tolearn ds
相关产品推荐
相关产品推荐

