[英]Python # Pyinstaller build problem on using Text Fsm
我做了一個簡單的程序,使用 Python 訪問 CISCO 設備。 為此,我正在使用 Netmiko Textfsm 方法。 當我使用 pyinstaller 構建 an.exe 時,它工作正常。 但是,如果我將 .exe 復制到另一台 PC,則會顯示錯誤:
未找到包含 TextFSM 索引文件的目錄。
請將NET_TEXTFSM環境變量設置為指向包含您的 TextFSM 索引文件的目錄。
或者,
pip install ntc-templates
(如果使用 ntc-templates)。
我怎樣才能克服這個問題?
問題是您需要在這里使用絕對路徑而不是相對路徑:
os.environ["NET_TEXTFSM"] = "lib/ntc-templates/templates"
os.path.join 應該使用如下絕對路徑,因為這里不支持相對路徑:
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.