#1
|
|||
|
|||
Using YAML in Python with SecureCRT
I'm trying to extract and parse a YAML config file on a Windows system, but I'm unable to successfully import yaml from within a SecureCRT python script. The weird thing is, I'm able to do this no problem on a Linux system. I realize part of this might be because YAML isn't included with SecureCRT's python, but what I don't understand is why it works in Linux but not Windows. Any suggestions?
Last edited by pjano1; 06-22-2020 at 11:29 AM. |
#2
|
||||
|
||||
Hello "pjano1",
Because python is not natively available on a stock Windows machine, SecureCRT for Windows provides a limited Python environment; it's not a comprehensive Python distribution. Additionally, external third-party Python modules cannot be imported into this limited Python environment within SecureCRT on Windows. I've added a feature request for the ability to include the yaml library/module you want in SecureCRT's limited Python environment. I've also added a feature request for the ability to use a completely separate Python environment, rather than the limited Python environment that is currently shipping with SecureCRT, in case you wanted to go with a third-party Python environment on your Windows machine. I don't yet have any ETA for when or even if these might ever become available, but if either does we can post here for notification. If you prefer direct email notification, send an email to support@vandyke.com with a subject of Please notify: Feature Requests - Forum Thread #14215. --Jake
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
#3
|
|||
|
|||
Hi Jake,
Thanks for both of the feature requests. For now I could probably switch to a format other than YAML that could still work with the limited Python environment. But, YAML is my preference so if either of those features become available in the future that would be huge. To add on to my original question, I am able to work with YAML in SecureCRT for Linux. Is this because this version of SecureCRT has a more robust Python environment than Windows? |
#4
|
||||
|
||||
Quote:
SecureCRT for mac/Linux environments uses the Python engine/environment that is natively installed and available on stock installs of supported operating systems.
--Jake
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
#5
|
|||
|
|||
I was able to get yaml working in Windows 10 x64, SecureCRT v8.7.1 by downloading the yaml source and setting the path to it.
Specifically: From https://pyyaml.org/wiki/PyYAML I downloaded the TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-5.3.1.tar.gz Unpacked it somewhere. My test(**) SecureCRT script looks like this: Code:
# $language = "Python" # $interface = "1.0" import sys # tell Python where to also look for libraries (**) yaml_path = "D:\\dev\\PyYAML-5.3.1\\lib" if yaml_path not in sys.path: sys.path.append(yaml_path) crt.Dialog.MessageBox("\n".join(sys.path)) import yaml data = yaml.load(""" name: Vorlin Laruknuzum sex: Male class: Priest title: Acolyte hp: [32, 71] sp: [1, 13] gold: 423 inventory: - a Holy Book of Prayers (Words of Wisdom) - an Azure Potion of Cure Light Wounds - a Silver Wand of Wonder""") crt.Dialog.MessageBox(data['name']) crt.Dialog.MessageBox(data['inventory'][1]) **Note2: It looks like SecureCRT also loads libraries from a few places by default, so you could probably put the "yaml" directory in one of these places also: C:\Program Files\VanDyke Software\SecureCRT\PythonLibraries -or- C:\Program Files\VanDyke Software\SecureCRT\SitePackages of course, depends on your install path and you might need to make the final directory. In which case you won't need to mess with sys.path. |
#6
|
|||
|
|||
Hi Gregg,
Thanks for sharing your workaround with the forum community! ![]() Please note that we have not tested this out, and since this support is not available natively we will not be able to troubleshoot any issues that may arise as a result of this implementation.
__________________
Thanks, --Brittney VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#7
|
||||
|
||||
Quote:
SecureCRT version 9.0 for Windows now supports the use of a separate python engine/environment. If you want to try it out to see if it will better meet your needs, you can read more about using Python 3 in SecureCRT 9.0 in this forum post. Is that something you would be willing to explore?
__________________
Jake Devenport VanDyke Software Technical Support YouTube Channel: https://www.youtube.com/vandykesoftware Email: support@vandyke.com Web: https://www.vandyke.com/support |
![]() |
Tags |
python , python import |
Thread Tools | |
Display Modes | Rate This Thread |
|
|