【发布时间】:2018-10-22 23:29:57
【问题描述】:
我今天更新了我的电脑,当我尝试导入 pandas 时收到以下错误消息:
import pandas as pd
AttributeError: module 'numpy' has no attribute '__version__'
我已经尝试了以下链接中的建议:
- AttributeError: 'module' object has no attribute '__version__'
- AttributeError: 'module' object has no attribute '__version__'
除了 numpy 包之外,我没有任何文件名 numpy.py。
我在 Windows 10 中运行 anaconda2,并创建了一个 python 3.5 虚拟环境。
以下是完整的错误信息:
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__'
编辑:执行以下命令会出错
import numpy
print(numpy.__file__)
AttributeError: module 'numpy' has no attribute '__file__'
print(numpy.version.version)
AttributeError: module 'numpy' has no attribute 'version'
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:以下命令产生以下输出:
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>
【问题讨论】:
-
import numpy; print(numpy.__file__)说什么? -
你也可以试试 import numpy; numpy.version.version Out[1]: '1.14.3'
-
@AnthonySottile - 我收到这条消息:----> 1 print(numpy.__file__) AttributeError: module 'numpy' has no attribute 'file'
-
@NaN 我得到这个响应 ----> 1 numpy.version.version AttributeError: module 'numpy' has no attribute 'version'
-
在我的应用程序中在 Linux 上使用 1.14.3 时出现此错误。如果我执行 pip install --upgrade numpy(升级到 1.14.5),错误就会消失。
标签: python python-3.x pandas numpy