Netmiko TEXTSFM Windows 10 问题

问题描述

我在 Windows 10 计算机上运行 Python 3。
当我运行它时,它工作正常。当我将 use_textfsm=True 添加到结果中时,模板所在的位置出现权限错误
权限似乎没问题。我想尝试将模板文件夹复制到新位置,但我不确定如何告诉 netmiko 该文件夹的新位置。

from nornir import Initnornir
from nornir.core.task import Result,Task
from nornir_netmiko.tasks.netmiko_send_command import netmiko_send_command
from nornir_utils.plugins.functions import print_result

nr = Initnornir("h:/Scripts/IPvZero-master/nornir_textFSM_video/config.yaml")
results = nr.run(netmiko_send_command,command_string="show interface switchport")
print_result(results)

TextFSM 集成
Netmiko 已配置为自动在 ~/ntc-template/templates/index 中查找 ntc-templates 索引文件
或者,您可以通过设置 NET_TEXTFSM 环境变量来明确告诉 Netmiko 在哪里查找 TextFSM 模板目录
(注意,此目录下必须有索引文件):

export NET_TEXTFSM=/path/to/ntc-templates/templates/

解决方法

我已经在这种环境中遇到过同样的问题。

环境

Python 3.9.4
testfsm==1.1.0
netmiko==3.4.0

您收到的错误消息是解决方案,但您可能误解了它。您应该执行以下操作:

  1. 转到控制面板 > 查看高级系统设置,然后点击环境变量

  2. 系统变量(不是用户名的用户变量)点击新建并添加以下内容变量:

    变量名称:NET_TEXTFSM

    变量值:%APPDATA%\Python\Python39\site-packages\ntc_templates\templates(验证 Windows 资源管理器中确实存在路径)

  3. 重启你的文本编辑器。

如果它不起作用,请重新启动您的电脑并重试。

我已经在 #1664

添加了这个解决方案