Mac下终端与PyCharm Python版本不一致致pandas无法导入的解决方法
解决Python版本不一致导致的PyCharm无法导入pandas问题
方法一:给PyCharm使用的Python 3.10安装pandas
方式1:PyCharm内直接安装
- 打开PyCharm,进入
File > Settings > Project: [你的项目名] > Python Interpreter - 点击右上角的
+号,搜索pandas,选中后点击Install Package完成安装
方式2:终端指定Python版本安装
在终端执行对应版本的pip命令:
python3.10 -m pip install pandas
方法二:让PyCharm切换到终端使用的Python 3.9环境
- 打开PyCharm,进入
File > Settings > Project: [你的项目名] > Python Interpreter - 点击 interpreter 右侧的下拉框,选择
Show All... - 点击
+号,选择System Interpreter,找到终端里的Python3.9路径(常见路径为/usr/local/bin/python3.9或/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9) - 选中后点击
OK,应用设置即可,之后PyCharm会使用已安装pandas的3.9环境
方法三:统一终端和PyCharm的Python版本(可选)
如果想长期统一默认Python版本,可修改终端配置:
- 查看当前Python3路径:
which python3 - 若要让终端默认指向3.10,执行(使用bash则替换
.zshrc为.bashrc):
echo "alias python3=/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10" >> ~/.zshrc
- 重启终端后,执行
python3 --version确认版本,再用pip install pandas将库安装到统一环境中
内容的提问来源于stack exchange,提问作者Mhd
相关产品推荐
相关产品推荐

