pandas中的模块导入错误

时间:2013-05-05 17:20:43

标签: python module pandas importerror

我安装了pandas模块。它需要最新版本的numpy,我有旧的一个pip安装了pandas模块,它也安装了所有依赖项,包括numpy。当我尝试在我的代码中导入pandas模块时,我收到以下错误:

/Library/Python/2.6/site-packages/pytz/__init__.py:35: 
UserWarning: Module dateutil was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/dateutil/__init__.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
from pkg_resources import resource_stream
Traceback (most recent call last):
File "Python-3.py", line 10, in <module>
from pandas.io.data import DataReader
File "/Library/Python/2.6/site-packages/pandas/__init__.py", line 25, in <module>
import pandas.core.config_init
File "/Library/Python/2.6/site-packages/pandas/core/config_init.py", line 4, in <module>
from pandas.core.format import detect_console_encoding
File "/Library/Python/2.6/site-packages/pandas/core/format.py", line 25, in <module>
from pandas.tseries.period import PeriodIndex
File "/Library/Python/2.6/site-packages/pandas/tseries/period.py", line 7, in <module>
import pandas.tseries.offsets as offsets
File "/Library/Python/2.6/site-packages/pandas/tseries/offsets.py", line 3, in <module>
from pandas.tseries.tools import to_datetime
File "/Library/Python/2.6/site-packages/pandas/tseries/tools.py", line 19, in <module>
dateutil.__version__ == '2.0'):  # pragma: no cover
AttributeError: 'module' object has no attribute '__version__'

我无法弄清楚为什么会出现此错误以及如何纠正错误。

有人可以帮我解决这个问题吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

我在尝试导入QTSK包时遇到了同样的问题, 并显示完全相同的信息。

我发现在以下情况下不会显示该消息:

  1. 在导入QSTK之前导入numpy,
  2. 当我从/Library/Python/2.7/site-packages运行python时, 因为pkg_resources在 /Library/Python/2.7/site-packages/distribute-0.6.32-py2.7.egg。
  3. 当我在/Library/Python/2.7/site-packages中运行python时,
  4. site.path:

      
        
          

    打印(&#34; \ n&#34;。加入(sys.path中))
          /Library/Python/2.7/site-packages/distribute-0.6.32-py2.7.egg
          /Library/Python/2.7/site-packages/cx_Oracle-5.1.2-py2.7-macosx-10.8-intel.egg
          
          /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/Extras/lib/python
          /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
          /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
          /Library/Python/2.7/site-packages/PIL
          /Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
          

        
      
  5. 我在外面跑步时的
  6. site.path /Library/Python/2.7/site-packages

      
        
          

    打印(&#34; \ n&#34;。加入(sys.path中))
          
          /Library/Python/2.7/site-packages/distribute-0.6.32-py2.7.egg
          /Library/Python/2.7/site-packages/cx_Oracle-5.1.2-py2.7-macosx-10.8-intel.egg
          /Library/Python/2.7/site-packages
          /用户/ ssgam / QSTK
          /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/Extras/lib/python
          /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
          /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
          /Library/Python/2.7/site-packages/PIL
          /Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
          

        
      

    请注意第一行是空的,而不是/Library/Python/2.7/site-packages。

  7. 看起来像加载/查找包的顺序有问题。

  8. 设置

  9. PYTHONPATH = /库/ Python的/ 2.7 /站点包/分发-0.6.32-py2.7.egg
    出口PYTHONPATH

    问题已经消失。

  10. 你的问题也是...... SAM