Python AttributeError: 模块 'numpy' 没有属性 '__version__'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50311096/
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-08-19 19:27:40  来源:igfitidea点击:

AttributeError: module 'numpy' has no attribute '__version__'

pythonpython-3.xpandasnumpy

提问by ktj1989

I updated my computer today, and am getting the following error message when I attempt to import pandas:

我今天更新了我的电脑,当我尝试导入 Pandas 时收到以下错误消息:

import pandas as pd        
AttributeError: module 'numpy' has no attribute '__version__'

I have tried the suggestions from the following links:

我已经尝试了以下链接中的建议:

  1. AttributeError: 'module' object has no attribute '__version__'
  2. AttributeError: 'module' object has no attribute '__version__'
  1. AttributeError: 'module' 对象没有属性 '__version__'
  2. AttributeError: 'module' 对象没有属性 '__version__'

I do not have any files names numpy.py other than the numpy package.

除了 numpy 包之外,我没有任何文件名 numpy.py。

I am running anaconda2 within windows 10, and have created a python 3.5 virtual environment.

我在 Windows 10 中运行 anaconda2,并创建了一个 python 3.5 虚拟环境。

Following is the full error message:

以下是完整的错误消息:

Python 3.5.5 | packaged by conda-forge | (default, Apr  6 2018, 16:03:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\j267156\AppData\Local\Continuum\anaconda2\envs\sf35\lib\site-packages\pandas\__init__.py", line 23, in <module>
    from pandas.compat.numpy import *
  File "C:\Users\j267156\AppData\Local\Continuum\anaconda2\envs\sf35\lib\site-packages\pandas\compat\numpy\__init__.py", line 10, in <module>
    _np_version = np.__version__
AttributeError: module 'numpy' has no attribute '__version__'

Edit: performing the following commands gives an error

编辑:执行以下命令会出错

import numpy
print(numpy.__file__)
AttributeError: module 'numpy' has no attribute '__file__'
print(numpy.version.version)
AttributeError: module 'numpy' has no attribute 'version'

Edit2: perfoming the following commands gives me the following errors:

Edit2:执行以下命令给我以下错误:

import numpy as np
np.zeros(5)
#AttributeError: module 'numpy' has no attribute 'zeros'
vars(np).keys()
#dict_keys(['__name__', '__package__', '__spec__', '__loader__', '__doc__', '__path__'])

Edit3: the following commands result in the following output:

Edit3:以下命令产生以下输出:

import numpy as np    
In [7]: np.__path__
    Out[7]: _NamespacePath(['C:\Users\j267156\AppData\Local\Continuum\anaconda2\envs\sf35\lib\site-packages\numpy'])

    In [8]: np.__loader__
    Out[8]: <_frozen_importlib_external._NamespaceLoader at 0x2033a3c8080>

回答by Sathick Ibrahim

Try this

尝试这个

In Jupyter notebook first uninstall the existing numpy by using !pip uninstall numpy.

在 Jupyter notebook 中,首先使用!pip uninstall numpy卸载现有的numpy

Then install it !pip install numpy. Now restart the kernel(Python Notebook). It will work.

然后安装它!pip install numpy。现在重新启动内核(Python Notebook)。它会起作用。

回答by Kim Reece

Just had this issue after conda chose to update numpy from 1.13.3 to 1.14.3. Reverting numpy via procedure in http://blog.rtwilson.com/conda-revisions-letting-you-rollback-to-a-previous-version-of-your-environment/sufficed to recover functionality, followed by pinning the version in the environment.

在 conda 选择将 numpy 从 1.13.3 更新到 1.14.3 后才遇到这个问题。通过http://blog.rtwilson.com/conda-revisions-letting-you-rollback-to-a-previous-version-of-your-environment/ 中的过程恢复 numpy足以恢复功能,然后将版本固定在环境。

回答by AbdulRahim Khan

You may have named your program/script 'numpy'. I also had that then i renamed my program and then it works. It happens because when you name your program similar to a module the import attribute clashes between programs and modules

您可能已将您的程序/脚本命名为“numpy”。我也有,然后我重命名了我的程序,然后它就可以工作了。发生这种情况是因为当您将程序命名为类似于模块时,程序和模块之间的导入属性会发生冲突

回答by Tomasz Bartkowiak

Have you tried this:

你有没有试过这个

pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy