繁体   English   中英

ModuleNotFoundError:没有名为“pyzabbix”的模块

[英]ModuleNotFoundError: No module named 'pyzabbix'

pyzabbix是此脚本工作所需的模块。 我使用 pip 安装它,请参阅下面的确认:

  WARNING: The script chardetect.exe is installed in 'C:\Users\Christopher Ezimoha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2019.11.28 chardet-3.0.4 idna-2.8 pyzabbix-0.7.5 requests-2.22.0 urllib3-1.25.8
C:\Users\Christopher Ezimoha\Desktop>

但是,我在第 24 行收到一个错误,提示找不到该模块。 我不确定我需要做什么。 请参阅下面的脚本并提出相应建议,因为我需要此代码来读取 CSV 文件并更新名为Zabbix的应用程序。

def addHosts(zapi):
    # Add Hosts

    file = open('hosts.csv', 'r')
    reader = csv.reader(file)
    devicelist = list(reader)
    import csv

    def login():
        # Login/authenticate below
        session = ZabbixAPI('https://zabbix.xxxxxx.xxx')
        # session = ZabbixAPI('http://xxxxxxxxxx/zabbix')
        session.login(user="xxxxxxxxxxxx", password="xxxxxxxx")
        print("Connected to Zabbix API Version %s" % session.api_version())
        return session

    for row in devicelist:
        device = row[0]
        hostgroup = row[1]
        responsegroup = zapi.hostgroup.get(filter={'name': hostgroup})
        groupid = responsegroup[0]['groupid']
        ip = row[2]
        templatePriority = row[3]
        responsepriority = zapi.template.get(filter={'name': templatePriority})
        templatePriorityId = responsepriority[0]['templateid']
#        if templatePriority == 'P1':
#            templatePriorityId = '40874'
        templateType = row[4]
        responsetype = zapi.template.get(filter={'name': templateType})
        templateTypeId = responsetype[0]['templateid']
        try:
            response = zapi.host.create(
                host=device,
                interfaces=[{
                    'type': 2,
                    'main': 1,
                    'ip': ip,
                    'dns': '',
                    'port': 161,
                    'useip': 1
                }],
                groups=[{
                    'groupid': groupid}],
                templates=[{'templateid': templatePriorityId}, {'templateid': templateTypeId}],
                inventory_mode=1
            )

            print("Created new host: " + device)
        except ZabbixAPIException as e:
            if 'already exists' in e[0]:
                print("Already created host " + device)
            else:
                print(e[0])
    return


def main():
    #    hostgroup = raw_input('Hostgroup: ')
    #hostgroup = "ALTC - Altcar"
    zapi = login()
    addHosts(zapi)
    return


if __name__ == '__main__':
    main()

您是否同时安装了 python 2 和 3? 如果两者都有, pip会在python2下安装模块。 如果您希望将模块安装在python3下,请尝试像这样安装:

pip3 install pyzabbix
  1. 在您包含在问题中的代码中没有import
from pyzabbix import ZabbixAPI
  1. login()函数应该在addHosts()之外定义,以便像在main()那样调用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM