Ubuntu 服务器 23.04 netplan cloud-init python 错误

Ubuntu 服务器 23.04 netplan cloud-init python 错误

我以前也曾尝试自己寻找解决方案和答案,但没有成功。

我最近更改了我的 Wi-Fi SSID,因此必须在我的 ubuntu 服务器配置中反映该更改。

拉斯皮4一切按预期工作并且设备连接到新的 SSID。

树莓派 3我重复了与 rapi 4 上相同的步骤,但是任何与之相关netplancloud-init导致回溯错误的命令都向我抛出。

系统设置和状态

  • 在两台树莓派(3 和 4)上运行 Ubuntu 服务器 23.04
  • 两个系统都是最新的
  • 更改了两个文件中的配置/boot/firmware/network-config以反映新的 SSID
  • 三重检查是否存在语法错误或缩进问题
  • 执行netplan trynetplan apply

问题描述

  • 执行任何netplancloud-init命令都会输出错误。即使我尝试运行非常基本的命令netplan -h,也会cloud-init -h出现相同的错误。

参见下面的日志:

> netplan -h
Traceback (most recent call last):
  File "/usr/sbin/netplan", line 23, in <module>
    netplan.main()
  File "/usr/share/netplan/netplan/cli/core.py", line 48, in main
    self.parse_args()
  File "/usr/share/netplan/netplan/cli/core.py", line 41, in parse_args
    import netplan.cli.commands
  File "/usr/share/netplan/netplan/cli/commands/__init__.py", line 21, in <module>
    from netplan.cli.commands.migrate import NetplanMigrate
  File "/usr/share/netplan/netplan/cli/commands/migrate.py", line 26, in <module>
    import yaml
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 936, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1069, in get_code
  File "<frozen importlib._bootstrap_external>", line 729, in _compile_bytecode
EOFError: marshal data too short
> cloud-init -h
Traceback (most recent call last):
  File "/usr/bin/cloud-init", line 33, in <module>
    sys.exit(load_entry_point('cloud-init==23.2.1', 'console_scripts', 'cloud-init')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/cloud-init", line 25, in importlib_load_entry_point
    return next(matches).load()
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 27, in <module>
    from cloudinit.config.modules import Modules
  File "/usr/lib/python3/dist-packages/cloudinit/config/modules.py", line 14, in <module>
    from cloudinit import config, importer
  File "/usr/lib/python3/dist-packages/cloudinit/importer.py", line 15, in <module>
    from cloudinit import util
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 46, in <module>
    from cloudinit import (
  File "/usr/lib/python3/dist-packages/cloudinit/safeyaml.py", line 11, in <module>
    import yaml
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 936, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1069, in get_code
  File "<frozen importlib._bootstrap_external>", line 729, in _compile_bytecode
EOFError: marshal data too short
  • 检查/var/log/syslog只是为了找到更多明显与 python3 相关的错误,即在apt_news.pyesm_cache.py

到目前为止我尝试过

  • 使用以下方法重新安装 netplan、cloud-init 甚至 pythonapt --reinstall install <package>
  • 清除 netplan 和 cloud-init 并重新安装
  • 检查是否有任何丢失或破损的包裹

就我有限的知识而言,似乎发生了一些常见的 Python 错误,但我不知道如何解决它。请考虑一下我对 Linux/ubuntu 的了解,因为我在疫情期间花了很多时间学习教程,将 Raspberry Pi 设置为家庭服务器,所以我对 Linux/ubuntu 的了解还比较基础。

我将不胜感激任何可能引导我走向正确方向的意见或提示:)

相关内容