pandas AttributeError: 'module' 对象没有属性 'version'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36137200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 00:54:40  来源:igfitidea点击:

AttributeError: 'module' object has no attribute 'version'

python-2.7pandas

提问by Greg

I am working on learning how to use pandas but get the following error:

我正在学习如何使用Pandas,但出现以下错误:

Traceback (most recent call last):
  File "data_frame.py", line 2, in <module>
    import pandas as pd
  File "/Users/gregwinter/anaconda2/lib/python2.7/site-packages/pandas/__init__.py", line 13, in <module>
    __import__(dependency)
  File "/Users/gregwinter/numpy.py", line 22, in <module>
    from pandas.compat.numpy_compat import *
  File "/Users/gregwinter/anaconda2/lib/python2.7/site-packages/pandas/compat/numpy_compat.py", line 15, in <module>
    _np_version = np.version.short_version
AttributeError: 'module' object has no attribute 'version'

I have no idea how to fix this. Anything you can tell be on how to fix this would be great.

我不知道如何解决这个问题。你能告诉我如何解决这个问题的任何东西都会很棒。

回答by DSM

You named a file of your ownnumpy.py:

您命名了自己的文件numpy.py

/Users/gregwinter/numpy.py

Guess which one Python thinks pandas wants to import? :-) Rename your program, and remove any .pyc or .pyo files that are around.

猜猜 Python 认为 pandas 想要导入的是哪一种?:-) 重命名您的程序,并删除周围的任何 .pyc 或 .pyo 文件。

回答by mdgis

I experienced this same problem after upgrading Jupyter, but did not have a local file named numpy.py. I was able to fix the issue on an Anaconda build by uninstalling/reinstalling pandas using: conda remove pandasand then conda install pandas

升级 Jupyter 后我遇到了同样的问题,但没有名为 numpy.py 的本地文件。我能够通过使用以下方法卸载/重新安装Pandas来解决 Anaconda 构建的问题:conda remove pandas然后conda install pandas

Problem was fixed.

问题已解决。