2017-06-05 17 views
0

スクリプトで同じpythonコードを使用し、cliで直接使用します。 cliではコードはエラーなしで動作しますが、スクリプトではエラーが発生します。jsonpath pythonモジュール:モジュール 'jsonpath'には属性 'jsonpath'がありません

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) [[email protected] 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

答えて

0

モジュールjsonpathは古いです。私はそれを使用しないことで問題を解決しました。 私は最終的に次のコードを使用します:

関連する問題