系统相关
首页 > 系统相关> > 「解决」RuntimeError: Couldn‘t detect Bash version, shell completion is not supported

「解决」RuntimeError: Couldn‘t detect Bash version, shell completion is not supported

作者:互联网

这个问题发生在激活 idf 环境的时候,环境正常激活了,但也报出了这一串异常。

$ get_idf
Setting IDF_PATH to '/opt/esp-idf'
Detecting the Python interpreter
Checking "python" ...
Python 3.9.7
"python" has been detected
Adding ESP-IDF tools to PATH...
Using Python interpreter in /home/kearney/.espressif/python_env/idf4.3_py3.9_env/bin/python
Checking if Python packages are up to date...
Python requirements from /opt/esp-idf/requirements.txt are satisfied.
Added the following directories to PATH:
  /opt/esp-idf/components/esptool_py/esptool
  /opt/esp-idf/components/espcoredump
  /opt/esp-idf/components/partition_table
  /opt/esp-idf/components/app_update
  /home/kearney/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin
  /home/kearney/.espressif/tools/xtensa-esp32s2-elf/esp-2020r3-8.4.0/xtensa-esp32s2-elf/bin
  /home/kearney/.espressif/tools/xtensa-esp32s3-elf/esp-2020r3-8.4.0/xtensa-esp32s3-elf/bin
  /home/kearney/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf/bin
  /home/kearney/.espressif/tools/esp32ulp-elf/2.28.51-esp-20191205/esp32ulp-elf-binutils/bin
  /home/kearney/.espressif/tools/esp32s2ulp-elf/2.28.51-esp-20191205/esp32s2ulp-elf-binutils/bin
  /home/kearney/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210401/openocd-esp32/bin
  /home/kearney/.espressif/python_env/idf4.3_py3.9_env/bin
  /opt/esp-idf/tools
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:

  idf.py build

Traceback (most recent call last):
  File "/opt/esp-idf/tools/idf.py", line 812, in <module>
    main()
  File "/opt/esp-idf/tools/idf.py", line 730, in main
    cli(sys.argv[1:], prog_name=PROG, complete_var='_IDF.PY_COMPLETE')
  File "/home/kearney/.espressif/python_env/idf4.3_py3.9_env/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/kearney/.espressif/python_env/idf4.3_py3.9_env/lib/python3.9/site-packages/click/core.py", line 1057, in main
    self._main_shell_completion(extra, prog_name, complete_var)
  File "/home/kearney/.espressif/python_env/idf4.3_py3.9_env/lib/python3.9/site-packages/click/core.py", line 1132, in _main_shell_completion
    rv = shell_complete(self, ctx_args, prog_name, complete_var, instruction)
  File "/home/kearney/.espressif/python_env/idf4.3_py3.9_env/lib/python3.9/site-packages/click/shell_completion.py", line 45, in shell_complete
    echo(comp.source())
  File "/home/kearney/.espressif/python_env/idf4.3_py3.9_env/lib/python3.9/site-packages/click/shell_completion.py", line 324, in source
    self._check_version()
  File "/home/kearney/.espressif/python_env/idf4.3_py3.9_env/lib/python3.9/site-packages/click/shell_completion.py", line 319, in _check_version
    raise RuntimeError(
RuntimeError: Couldn't detect Bash version, shell completion is not supported.

【问题解决】RuntimeError: Couldn‘t detect Bash version, shell completion is not supported… 麟枫 2021-08-06 给出了一种临时解决办法: 修改shell_completion.py 里305行那的两行代码

output = subprocess.run(["bash", "-c", "echo $BASH_VERSION"], stdout=subprocess.PIPE)
match = re.search(r"(\d)\.(\d)\.\d", output.stdout.decode())

原来的代码(shell_completion.py L302-L321)是这样的

    def _check_version(self) -> None:
        import subprocess

        output = subprocess.run(["bash", "--version"], stdout=subprocess.PIPE)
        match = re.search(r"version (\d)\.(\d)\.\d", output.stdout.decode())

        if match is not None:
            major, minor = match.groups()

            if major < "4" or major == "4" and minor < "4":
                raise RuntimeError(
                    _(
                        "Shell completion is not supported for Bash"
                        " versions older than 4.4."
                    )
                )
        else:
            raise RuntimeError(
                _("Couldn't detect Bash version, shell completion is not supported.")
            )

可以从源码中看出这个问题抛出异常是因为没有检测到 bash 的版本号,然而我已经安装了最新版的 bash,而且通过 L305 行的 bash --version 是可以获取到版本号的,再看一下代码抛出异常的原因是 match 为 None,也就是说 L306 没有检测到 bash 的版本号,为什么呢??通过下面的输出对比一下就知道了,它的版本号校验是通过检测 version 后面的数字,然而我使用的是中文环境,所以它一定不会检测到版本。

$ bash --version
GNU bash,版本 5.1.8(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
许可证 GPLv3+: GNU GPL 许可证第三版或者更新版本 <http://gnu.org/licenses/gpl.html>

本软件是自由软件,您可以自由地更改和重新发布。
在法律许可的情况下特此明示,本软件不提供任何担保。

那解决办法其实也比较简单,需要将这个语言环境变量设置为英文,短期方案是临时设置语言环境变量为英文 export LANG=en_US;中长期方案一是修改系统语言为英文,中长期方案二是把环境修改设置到启动命令中 alias get_idf='export LANG=en_US && . /opt/esp-idf/export.sh',永久解决方案是反馈该问题到上游,主线已经合并解决方案,下一个稳定版发布即可永久解决该问题。

标签:completion,detect,Couldn,esp,espressif,env,idf,home,kearney
来源: https://blog.csdn.net/weixin_43031092/article/details/120575411