Linux安装Pandas报错:AttributeError: module 'numpy' has no attribute 'get_include'
解决pip安装pandas时出现的numpy.get_include()错误
错误原因
报错AttributeError: module 'numpy' has no attribute 'get_include'说明当前系统中的numpy模块存在异常——要么是安装不完整、文件损坏,要么是版本与要安装的pandas(1.3.5)不兼容,导致关键方法缺失。
解决步骤
1. 彻底卸载现有numpy
执行命令强制卸载当前numpy,避免残留文件干扰:
pip uninstall -y numpy
如果系统存在多个Python版本,建议用python -m pip确保调用对应版本的pip:
python -m pip uninstall -y numpy
2. 安装与pandas 1.3.5兼容的numpy版本
pandas 1.3.5要求numpy版本≥1.17.3,推荐安装稳定兼容的1.21.6版本:
pip install numpy==1.21.6
同样,多Python版本环境下用:
python -m pip install numpy==1.21.6
3. 重新安装pandas
完成numpy安装后,再安装pandas:
pip install pandas==1.3.5
或者一步到位:
python -m pip install numpy==1.21.6 pandas==1.3.5
额外排查点
如果执行上述步骤后仍报错,检查是否存在以下情况:
- 系统中存在多个Python环境(如virtualenv、conda),确认当前终端处于正确的环境中
- 权限不足导致安装不完整,可添加
sudo(系统级安装)或使用--user参数(用户级安装):pip install --user numpy==1.21.6 pandas==1.3.5
内容的提问来源于stack exchange,提问作者Catarina Ribeiro
相关产品推荐
相关产品推荐

