numpy load 引发“AttributeError: 'module”;对象没有属性“expr””

发布于 2024-10-03 20:31:59 字数 1405 浏览 8 评论 0原文

我尝试运行

#!/usr/bin/env python

import os
from numpy import *

b= ones((3, 3))  
print b  
save('fff',  b)  
a = load('fff.npy')  
print a.shape  
print 'fertig'

但它引发:

Traceback (most recent call last):  
  File "savetest.py", line 9, in <module>  
    a = load('fff.npy')  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 195, in load  
    return format.read_array(fid)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/format.py", line 353, in read_array  
    shape, fortran_order, dtype = read_array_header_1_0(fp)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/format.py", line 250, in   read_array_header_1_0  
    d = safe_eval(header)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/utils.py", line 840, in safe_eval  
    ast = compiler.parse(source, "eval")  
  File "/usr/lib/python2.6/compiler/transformer.py", line 53, in parse  
    return Transformer().parseexpr(buf)  
  File "/usr/lib/python2.6/compiler/transformer.py", line 132, in parseexpr  
    return self.transform(parser.expr(text))  
AttributeError: 'module' object has no attribute 'expr'  

我尝试了 文档中的示例。 scipy.org 它在我的终端中引发了相同的错误,但它在我的 ERIC python IDE 中工作。目前互联网没有为我提供可理解或可转移的解决方案。

最后, 有人看到我的代码或方法中的错误并能够提供解决方案吗?

I try to run

#!/usr/bin/env python

import os
from numpy import *

b= ones((3, 3))  
print b  
save('fff',  b)  
a = load('fff.npy')  
print a.shape  
print 'fertig'

but it raises:

Traceback (most recent call last):  
  File "savetest.py", line 9, in <module>  
    a = load('fff.npy')  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 195, in load  
    return format.read_array(fid)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/format.py", line 353, in read_array  
    shape, fortran_order, dtype = read_array_header_1_0(fp)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/format.py", line 250, in   read_array_header_1_0  
    d = safe_eval(header)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/utils.py", line 840, in safe_eval  
    ast = compiler.parse(source, "eval")  
  File "/usr/lib/python2.6/compiler/transformer.py", line 53, in parse  
    return Transformer().parseexpr(buf)  
  File "/usr/lib/python2.6/compiler/transformer.py", line 132, in parseexpr  
    return self.transform(parser.expr(text))  
AttributeError: 'module' object has no attribute 'expr'  

I tried the example from docs.scipy.org it raises the same error in my terminal, but it works in my ERIC python IDE. The Internet provides no for me understandable or transferable solution at this time.

Finally,
does anyone see the error in my code or approach and is able to provide a solution for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倚栏听风 2024-10-10 20:31:59

我认为您的文件中的某个位置必须有另一个名为 parser.py 的文件(Python 可以找到的文件)。它是为了让 Python 找到错误的解析器模块。环顾四周,看看是否是这样。它也可能是一个 parser.so 文件。

尝试进入交互式会话并输入:

import parser
print parser.__file__

希望这能告诉您有问题的文件所在的位置。

I think you must have another file named parser.py somewhere in your files (the ones that Python can find). It is making it so that Python finds the wrong parser module. Look around and see if that is the case. It could be a parser.so file too.

Try going into an interactive session and typing:

import parser
print parser.__file__

Hopefully, that will tell you where the troublesome file is located.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文