无法从Windows命令行运行pyang命令,但可以从Git Bash运行

2024-06-25 22:43:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习python及其用于解析.yang文件的pyang库。我可以成功地安装python和pip。并通过cmd确认其工作正常。然后,我通过以下命令安装了pyang:

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)

但是,当我在Windows cmd中执行以下命令来解析yang文件时,我得到如下错误:

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

但是,当从Git Bash执行时,这可以很好地工作。pyang是否有一些内部linux依赖项


Tags: pip文件in命令cmdmylocalrequirement
2条回答

Pyang实际上是一个python脚本。Bash会很高兴地运行它,因为顶部有“shebang”。 Windows没有这样的概念,顶部的一行表示运行脚本的可执行文件,它依赖扩展来确定运行哪个程序。因此,我们必须手动将Windows引用到python

我发现运行pyang最简单的方法是通过命令行:

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

该命令的更完整版本为: python C:\path-to-Python-dir\Scripts\pyang -f tree "C:\path-to-Yang-file\___.yang"

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.

相关问题 更多 >