Python # Pyinstaller build problem on using Text Fsm

296 Views Asked by At

I made a simple program by using Python to access CISCO devices. I am using the Netmiko Textfsm method for this. When I build an .exe using pyinstaller it works fine. However, if I copy the .exe to another PC, it shows an error:

Directory containing TextFSM index file not found.

Please set the NET_TEXTFSM environment variable to point at the directory containing your TextFSM index file.

Alternatively, pip install ntc-templates (if using ntc-templates).

How can I overcome this problem?

1

There are 1 best solutions below

1
Baris Sonmez On

The issue is you need to use an absolute path and not a relative path here:

os.environ["NET_TEXTFSM"] = "lib/ntc-templates/templates"

os.path.join should use the absolute path as follows because relative paths are not supported here:

def get_structured_data(raw_output, platform, command):
            """Convert raw CLI output to structured data using TextFSM template."""
            template_dir = get_template_dir()
            index_file = os.path.join('/Users/barissonmez/ntc-templates/templates/', '/Users/barissonmez/ntc-templates/templates/index')
    '/Users/barissonmez/ntc-templates/templates/index'
            textfsm_obj = clitable.CliTable(index_file, template_dir)