1

I encountered that error:

import jmespath AttributeError: Module jmespath has no attribute search

I used the version 1.0.1 of this module.

I wanted to run the following code:

import jmespath

person = {
    "person": [
        {'id': 1, 'name': 'ali', 'age': 42, 'children': [
            {'name': 'sara', 'age': 7},
            {'name': 'sima', 'age': 15},
            {'name': 'sina', 'age': 2}
        ]},
        {'id': 2, 'name': 'reza', 'age': 65, 'children': []}
    ]
}

print(jmespath.search('person[*].children[?age>`10`].name', person))
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
alirhm
  • 13
  • 3

2 Answers2

1

Here is a way I was able to reproduce it, given the file hierarchy:

.
├── demo.py
└── jmespath.py

The file jmespath.py being empty and the demo.py file containing your code, I do get this error while executing it:

$ python3 demo.py 
Traceback (most recent call last):
  File "demo.py", line 13, in <module>
    print(jmespath.search('person[*].children[?age>`10`].name', person))
          ^^^^^^^^^^^^^^^
AttributeError: module 'jmespath' has no attribute 'search'

So, one possible fix is to ensure that you do not have a file named jmespath.py or a module named jmespath that would conflict with the library.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
0

Which version of Python are you using? If it's an older version, you can try running the code with a higher version of Python.

snowmoss
  • 17
  • 6