Mac Mojave下安装numpy==1.19.1失败与VS Code导入numpy/numba报错求助
解决方案
前置清理操作
执行pip uninstall numpy -y2-3次,彻底清理所有残留的numpy版本,避免多版本冲突导致pip list出现分发版本无效警告。
1. 安装numpy 1.19.1
优先选择conda安装,跳过源码编译流程,适配性更高:
- 激活目标conda虚拟环境后执行安装命令:
conda install -c conda-forge numpy==1.19.1
- 安装完成后执行
pip show numpy确认版本为1.19.1即可。
如果conda安装失败,修复编译环境后用pip安装:
- 先安装适配Mojave 10.14.6的Xcode 11.x版本命令行工具,不要使用最新版(最新版不兼容10.14系统)
- 用homebrew安装编译依赖:
brew install openblas gfortran
- 升级构建工具后指定参数安装:
pip install --upgrade setuptools wheel OPENBLAS="$(brew --prefix openblas)" pip install --no-cache-dir numpy==1.19.1
2. 安装适配版本numba
numpy 1.19.1最高适配numba 0.53.1版本,直接安装对应版本避免依赖冲突:
conda install -c conda-forge numba==0.53.1
安装完成后执行pip check确认无依赖冲突,pip list的警告会自动消失。
3. 修复VS Code导入报错
该报错为VS Code Python解释器选择不匹配导致,按以下步骤操作:
- 按下
Cmd + Shift + P调出命令面板,输入Python: Select Interpreter - 在列表中选中当前使用的conda虚拟环境对应的Python 3.8.10解释器,等待索引更新完成即可
- 若仍有报错,在项目
.vscode/settings.json中添加虚拟环境依赖路径配置:
{ "python.analysis.extraPaths": [ "/Users/你的用户名/opt/miniconda3/envs/你的环境名/lib/python3.8/site-packages" ] }
将路径中的用户名、环境名替换为你自己的实际路径即可。
内容的提问来源于stack exchange,提问作者thatsroughbuddy
相关产品推荐
相关产品推荐

