Netmiko and Textfsm Path and Env Issue Windows
See original GitHub issueI am currently trying to set up a test with Netmiko and Textfsm in Windows 10, but no matter what path I try to setup the textfsm environment variable, it still doesn’t pick it up and throws an error:
Valid ntc-templates not found, please install https://github.com/networktocode/ntc-templates and then set the NET_TEXTFSM environment variable to point to the ./ntc-templates/templates directory.
I tried setting the environment variable manually via system properties --> environment variables, but still get the same message. I tried absolute as well as relative paths and no go. Ideally a relative path as the template folder will alway be alongside the script calling it. It might be something simple but im totally missing it right now.
The folder structure:
My Code:
import os, json
from netmiko import Netmiko
from netmiko import NetMikoAuthenticationException
templates = os.path.dirname(os.path.abspath(__file__)) + '\\ntc-template\\templates\\'
os.environ['NET_TEXTFSM']= templates
print(os.environ['NET_TEXTFSM'])
###############################################################
#Can i set the env var from within the scirpt using python?
#os.system(f'cmd /c "set NET_TEXTFSM={templates}"')
###############################################################
switch = {'device_type': 'cisco_ios',
'ip': '192.168.0.20',
'username': 'cisco',
'password': 'cisco',
'secret': 'cisco',
'timeout': 10000,
'session_timeout': 10000}
try:
c = Netmiko(**switch)
c.enable()
show_ip_arp = c.send_command('show ip arp', use_textfsm=True)
print(json.dumps(show_ip_arp))
except Exception as e:
print(e)
I was hoping anyone points to what might be wrong or missing. I would love to avoid having to set up any environment variables via cmd unless it can be automated as well. The idea is whoever opens this py file gets all that’s needed to use textfsm.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top GitHub Comments
I finally found a solution to this issue:
(not User variables for username)click New and add the following variable: Variable name: NET_TEXTFSM Variable value: %APPDATA%\Python\Python39\site-packages\ntc_templates\templatesUPDATE:
I reproduced the error message to be available in the issue as well
EDIT:
Sometime the Environment Variable unber System Variables only doesn’t work. Add the Env Var in both User and System Variables. However, Env Var under System Variables should be enough.
Thanks @ktbyers! Have a great day
Yes, you should only be using
textfsm >= 1.1.0
at this point. Are you using the latest version of Netmiko (3.1.0)?I think this should all work fine, but let me know if it isn’t.