python已安装pandas库无法引入问题解决

问题

MacOX环境下python2.7,通过

sudo pip install --user pandas 

命令安装pandas库,反馈

Requirement already satisfied: pandas in ./Library/Python/2.7/lib/python/site-packages (0.24.2)
Requirement already satisfied: pytz>=2011k in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pandas) (2013.7)
Requirement already satisfied: numpy>=1.12.0 in /Library/Python/2.7/site-packages (from pandas) (1.16.5)
Requirement already satisfied: python-dateutil>=2.5.0 in ./Library/Python/2.7/lib/python/site-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in /Library/Python/2.7/site-packages (from python-dateutil>=2.5.0->pandas) (1.13.0)

进入python环境引入库

import pandas

反馈引入失败

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pandas

解决方法

引入失败原因是安装时显示的pandas已存在路径与当前版本python环境查找包路径不一致。可进入当前python环境,通过以下代码,找到当前版本python环境查找包路径

import sys
print(sys.path)

反馈

['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages','/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages/pip-19.3.1-py2.7.egg']

以/Library/开头的即为路径地址

'/Library/Python/2.7/site-packages'

之后通过以下命令重新配置pandas环境即可

sudo pip install --target=路径地址 pandas

例如:

sudo pip install --target=/Library/Python/2.7/site-packages pandas

配置结果

配置后再次引入,成功显示版本号
在这里插入图片描述

  • 7
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值