numpy load raises "AttributeError: 'module' object has no attribute 'expr'"

12,038

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.

Share:
12,038
Sebastian
Author by

Sebastian

Updated on July 20, 2022

Comments

  • Sebastian
    Sebastian almost 2 years

    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?

  • Sebastian
    Sebastian over 13 years
    There was indeed such a file in that directory. I renamed it. Now it works as it should. Thank you for making my day.
  • Abramodj
    Abramodj over 6 years
    This happened to me with a file called signal.py
  • Atti
    Atti over 6 years
    @Abramodj same thing happened to me because my file was called signal.py