jsonpath python 模块:模块 'jsonpath' 没有属性 'jsonpath'

jsonpath python module: module 'jsonpath' has no attribute 'jsonpath'

我在脚本中使用相同的 python 代码并直接在 cli 中使用。虽然在 cli 中代码没有错误,但在脚本中它给了我一个错误。

AttributeError: module 'jsonpath' has no attribute 'jsonpath'

代码:

import os
import click
import subprocess
import urllib.request
import json
import jsonpath

@cli.command()
@click.argument('search', required=False, nargs=-1)
def search(search):
    for srch in search:
        packs = urllib.request.urlopen("https://aur.archlinux.org//rpc/?v=5&type=search&arg="+srch).read()
        somejson = json.loads(packs)
        match = jsonpath.jsonpath(somejson, '$.results[*].Name,Version,Description')
        print(match)

我对 cli 和脚本使用相同的 virtualenv。

代码 cli:

(venv) [user@laptop pyapp]$ python
Python 3.6.1 (default, Mar 27 2017, 00:27:06) 
[GCC 6.3.1 20170306] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jsonpath
>>> import json
>>> import urllib.request
>>> jsontext = urllib.request.urlopen("https://aur.archlinux.org//rpc/?v=5&type=search&arg=teamviewer").read()
>>> somejson = json.loads(jsontext)
>>> match = jsonpath.jsonpath(somejson, '$.results[*].Name,Version,Description')
>>> print(match)
['teamviewer-quicksupport-beta', '11.0.52520-1', 'Teamviewer Quicksupport - All-In-One Software for Remote Support and Online Meetings - beta version', 'teamviewer10', '10.0.46203-1.1', 'All-In-One Software for Remote Support and Online Meetings', 'remmina-plugin-teamviewer', '1.2.3.0-1', 'A protocol plugin for Remmina to launch a TeamViewer connection.', 'teamviewer8', '8.0.20931-1', 'All-In-One Software for Remote Support and Online Meetings', 'teamviewer-quicksupport', '11.0.57095-2', 'Teamviewer Quicksupport - All-In-One Software for Remote Support and Online Meetings', 'teamviewer-openrc', '1.0-2', 'OpenRC scripts for teamviewer.', 'teamviewer-beta', '12.0.69753-1', 'All-In-One Software for Remote Support and Online Meetings - beta version', 'teamviewer11', '11.0.67687-1', 'All-in-one software for remote support and online meetings', 'teamviewer9', '9.0.32150-1', 'All-In-One Software for Remote Support and Online Meetings', 'teamviewer', '12.0.76279-6', 'All-In-One Software for Remote Support and Online Meetings']

我不明白代码有什么问题。 完整代码为here

模块 jsonpath 是旧的。我通过不使用它解决了这个问题。 我最终使用了以下代码:

@cli.command()
@click.argument('search', required=False, nargs=-1)
def search(search):
    """ Search AUR repositorie for package name. """
    for srch in search:
        packs = urllib.request.urlopen("https://aur.archlinux.org//rpc/?v=5&type=search&arg="+srch).read()
        print(type(packs))
        somejson = json.loads(packs)
        somej = somejson['results']
        print(type(somej))
        for pkg in somej:
            print("Name: "+pkg['Name'])
            print("Version: "+pkg['Version'])
            print("Desc: "+pkg['Description'])
            print("################")