为什么在安装成功后无法导入pandas?

时间:2015-11-21 05:15:03

标签: python-3.x pandas

我已经使用命令pip3.4安装pandas'安装了pandas。

Successfully installed pandas python-dateutil pytz numpy six
Cleaning up...

root@hwy:~# python3.4
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'pandas'

成功安装pandas后,为什么不能在python3.4中导入pandas?

root@hwy:/home/debian8# pip3.4 show pandas
---
Name: pandas
Version: 0.17.1
Location: /usr/local/python3.4/lib/python3.4/site-packages
Requires: python-dateutil, pytz, numpy
root@hwy:/home/debian8# echo "import sys; print sys.path"
import sys; print sys.path
root@hwy:/home/debian8# python3.4
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages',
 '/usr/lib/python3/dist-packages']

1 个答案:

答案 0 :(得分:6)

您的pandas已安装在此处:

/usr/local/python3.4/lib/python3.4/site-packages

但此路径不在sys.path

作为解决方法:

export PYTHONPATH=$PYTHONPATH:/usr/local/python3.4/lib/python3.4/site-packages

并在此终端内再次启动Python并导入pandas

如果此方法有效,请将上面的这一行(export PYTHONPATH...)添加到~/.bashrc或等效内容中,如果您使用其他外壳来获得更永久的解决方案。