如何修复 pio remote agent start: error: can't find Rust compiler

问题:

运行 pio remote agent start 时,当 PlatformIO 安装 Python 包时,你看到类似这样的错误日志

generating cffi module ‘build/temp.linux-armv7l-3.7/_openssl.c’

platformio_remote_build_output.txt
generating cffi module 'build/temp.linux-armv7l-3.7/_openssl.c'
creating build/temp.linux-armv7l-3.7
running build_rust

    =============================DEBUG ASSISTANCE=============================
    如果你看到编译错误,请尝试以下步骤来
    成功安装 cryptography:
    1) 升级到最新的 pip 并重试。这将修复大多数
        用户的错误。参见:https://pip.pypa.io/en/stable/installing/#upgrading-pip
    2) 阅读 https://cryptography.io/en/latest/installation/ 了解针对你的平台的特定
        说明。
    3) 查看我们的常见问题解答获取更多信息:
        https://cryptography.io/en/latest/faq/
    4) 确保你安装了最新的 Rust 工具链:
        https://cryptography.io/en/latest/installation/#rust

    Python: 3.7.3
    platform: Linux-5.10.60-v7l+-armv7l-with-debian-10.10
    pip: n/a
    setuptools: 58.2.0
    setuptools_rust: 0.12.1
    =============================DEBUG ASSISTANCE=============================
  错误:找不到 Rust 编译器

  如果你使用的是过时的 pip 版本,可能此包有预构建的 wheel 可用,但 pip 无法从中安装。从 wheel 安装将避免需要 Rust 编译器。

  要更新 pip,运行:

      pip install --upgrade pip

  然后重试包安装。

  如果你确实打算从源代码构建此包,请尝试从系统包管理器安装 Rust 编译器,并确保在安装期间它在 PATH 中。或者,rustup(可在 https://rustup.rs 获取)是下载和更新 Rust 编译器工具链的推荐方式。

  此包需要 Rust >=1.41.0。
  ----------------------------------------
  错误:cryptography 构建轮子失败
Successfully built pyopenssl
cryptography 构建失败
错误:无法为使用 PEP 517 的 cryptography 构建轮子,无法直接安装
Error: Traceback (most recent call last):
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/platformio/package/manager/core.py", line 127, in inject_contrib_pysite
    from OpenSSL import SSL
  File "/home/pi/.platformio/packages/contrib-pysite/OpenSSL/__init__.py", line 8, in <module>
  File "/home/pi/.platformio/packages/contrib-pysite/OpenSSL/crypto.py", line 12, in <module>
  File "/home/pi/.platformio/packages/contrib-pysite/cryptography/x509/__init__.py", line 8, in <module>
  File "/home/pi/.platformio/packages/contrib-pysite/cryptography/x509/base.py", line 18, in <module>
  File "/home/pi/.platformio/packages/contrib-pysite/cryptography/x509/extensions.py", line 20, in <module>
  File "/home/pi/.platformio/packages/contrib-pysite/cryptography/hazmat/primitives/constant_time.py", line 11, in <module>
ImportError: /home/pi/.platformio/packages/contrib-pysite/cryptography/hazmat/bindings/_constant_time.abi3.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/platformio/__main__.py", line 115, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/click/core.py", line 1665, in invoke
    super().invoke(ctx)
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/platformio/commands/remote/command.py", line 40, in cli
    inject_contrib_pysite(verify_openssl=True)
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/platformio/package/manager/core.py", line 129, in inject_contrib_pysite
    build_contrib_pysite_package(contrib_pysite_dir)
  File "/home/pi/.platformio/penv/lib/python3.7/site-packages/platformio/package/manager/core.py", line 156, in build_contrib_pysite_package
    subprocess.check_call(args + [dep])
  File "/usr/lib/python3.7/subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/pi/.platformio/penv/bin/python', '-m', 'pip', 'install', '--no-compile', '-t', '/home/pi/.platformio/packages/contrib-pysite', '--no-binary', ':all:', 'pyopenssl >= 16.0.0']' returned non-zero exit status 1.

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

解决方案

你需要使用以下命令安装 rust

install_rust.sh
sudo apt -y install rustc

然后再次运行原始命令:

pio_remote_agent_start_retry.sh
pio remote agent start

Check out similar posts by category: PlatformIO