2

I am learning about python and it's pyang library for parsing .yang files. I could successfully install both python and pip. And confirmed that they work fine through cmd. I then installed pyang through the command:

C:\_pyangWorkspace\pip install pyang
Requirement already satisfied: pyang in c:\users\my-local-directory\local\programs\python\python38\lib\site-packages (2.3.2)
Requirement already satisfied: lxml in c:\users\my-local-directory\local\programs\python\python38\lib\site-packages (from pyang) (4.5.2)

However when I execute the below command in Windows cmd to parse a yang file I get the error as below:

C:\_pyangWorkspace>pyang -f tree ietf-interfaces.yang
'pyang' is not recognized as an internal or external command,
operable program or batch file.

But this works fine when executed from a Git Bash. Are there some internal linux dependencies for pyang?

raikumardipak
  • 1,461
  • 2
  • 29
  • 49

2 Answers2

2

Pyang is actually a python script. Bash will happily run it because of the "shebang" at the top. Windows has no such notion of a line at the top referring to an executable to run a script, it relies on extensions to figure out which program to run. So we have to manually refer Windows to python.

I have found that the easiest way to run pyang is via commandline:

python C:\path-to-Python-dir\Scripts\pyang

A more complete version of that command would be: python C:\path-to-Python-dir\Scripts\pyang -f tree "C:\path-to-Yang-file\___.yang"

Koen_DB
  • 21
  • 3
1
It seems the EXE file location for Pyang cant be detected in Windows. Therefore even if you just hit the command "pyang", it fails because Windows cant find the location of the executable file.

Ideally when you install a tool e.g. Python, you should set Environment variable in Windows but with Pyang, its not possible to set the PATH and so it doesnt work in Windows.

Deb
  • 587
  • 4
  • 12