【问题标题】:Not able to run pyang command from Windows command line but able to run from Git Bash无法从 Windows 命令行运行 pyang 命令,但能够从 Git Bash 运行
【发布时间】:2020-08-06 18:20:50
【问题描述】:

我正在学习 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 依赖项?

【问题讨论】:

    标签: python yang


    【解决方案1】:

    Pyang 实际上是一个 python 脚本。由于顶部的“shebang”,Bash 会很高兴地运行它。 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"

    【讨论】:

      【解决方案2】:
      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.
      

      理想情况下,当您安装工具时,例如Python,你应该设置 Windows 中的环境变量,但使用 Pyang,它不可能 设置路径,所以它在 Windows 中不起作用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-12
        • 1970-01-01
        • 2016-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多