为什么 pip install libvirt-python 失败并说我需要安装 libvirt,即使安装了 libvirt?

Why is pip install libvirt-python failing and saying I need libvirt installed, even though libvirt is installed?

提问人:Dan Largo 提问时间:9/15/2023 最后编辑:Dan Largo 更新时间:9/15/2023 访问量:116

问:

我正在使用 Python v3.9.16 运行 RHEL 9.2,并且正在尝试安装 libvirt-python Python 包。我尝试使用 pip 和 pipenv 进行安装,但每次都遇到相同的错误。

我已经安装了 libvirt 和 KVM 软件包(通过 dnf)并正常工作。我能够通过 cli 与带有 virsh 的 VM 进行交互。

我已经阅读了堆栈上的其他类似帖子,这些解决方案对我不起作用。关于可能的问题是什么的任何建议?

$ pip install libvirt-python

Defaulting to user installation because normal site-packages is not writeable
Collecting libvirt-python
  Downloading libvirt-python-9.7.0.tar.gz (132 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 132.1/132.1 kB 6.0 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: libvirt-python
  Building wheel for libvirt-python (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for libvirt-python (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [51 lines of output]
      running bdist_wheel
      running build
      running build_py
      Package 'libvirt' was not found
      Traceback (most recent call last):
        File "/home/bill/.local/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/bill/.local/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/bill/.local/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 434, in build_wheel
          return self._build_with_temp_dir(
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 419, in _build_with_temp_dir
          self.run_setup()
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 341, in run_setup
          exec(code, locals())
        File "<string>", line 284, in <module>
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 989, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-cx5clem5/normal/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 364, in run
          self.run_command("build")
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 989, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/command/build.py", line 131, in run
          self.run_command(cmd_name)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 989, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-cx5clem5/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "<string>", line 166, in run
        File "<string>", line 35, in check_minimum_libvirt_version
        File "/usr/lib64/python3.9/subprocess.py", line 373, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['pkg-config', '--print-errors', '--atleast-version=0.9.11', 'libvirt']' returned non-zero exit status 1.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for libvirt-python
Failed to build libvirt-python
ERROR: Could not build wheels for libvirt-python, which is required to install pyproject.toml-based projects

以下是我安装的 libvirt 相关软件包:

$ sudo dnf list | grep libvirt

libvirt.x86_64                                       9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-client.x86_64                                9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon.x86_64                                9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-config-network.x86_64                 9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-config-nwfilter.x86_64                9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-interface.x86_64               9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-network.x86_64                 9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-nodedev.x86_64                 9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-nwfilter.x86_64                9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-qemu.x86_64                    9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-secret.x86_64                  9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-storage.x86_64                 9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-storage-core.x86_64            9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-storage-disk.x86_64            9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-storage-iscsi.x86_64           9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-storage-logical.x86_64         9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-storage-mpath.x86_64           9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-storage-rbd.x86_64             9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-driver-storage-scsi.x86_64            9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-daemon-kvm.x86_64                            9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-dbus.x86_64                                  1.4.1-5.el9                         @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-glib.x86_64                                  4.0.0-3.el9                         @rhel-9-for-x86_64-appstream-eus-rpms
libvirt-libs.x86_64                                  9.0.0-10.3.el9_2                    @rhel-9-for-x86_64-appstream-eus-rpms
pcp-pmda-libvirt.x86_64                              6.0.1-5.el9_2                       @rhel-9-for-x86_64-appstream-eus-rpms
python3-libvirt.x86_64                               9.0.0-1.el9                         @rhel-9-for-x86_64-appstream-eus-rpms
fence-virtd-libvirt.x86_64                           4.10.0-43.el9                       rhel-9-for-x86_64-appstream-eus-rpms
fence-virtd-libvirt.x86_64                           4.10.0-43.el9                       rhel-9-for-x86_64-appstream-rpms
libvirt-nss.x86_64                                   9.0.0-10.3.el9_2                    rhel-9-for-x86_64-appstream-eus-rpms
libvirt-nss.x86_64                                   9.0.0-10.3.el9_2                    rhel-9-for-x86_64-appstream-rpms
python rhel kvm libvirt rhel9

评论

0赞 John Gordon 9/15/2023
这个输出有点令人困惑。为什么它以 开头,然后下一行是 ?$ pip install libvirt-pythonlibvirt-experiment]$ pip install libvirt-python
0赞 Dan Largo 9/15/2023
对不起,这是复制/粘贴错误。我更新了帖子。
0赞 larsks 9/15/2023
您可能需要 libvirt 开发库 (),但为什么要运行而不是运行?libvirt-develpip install libvirt-pythondnf install python3-libvirt
0赞 Dan Largo 9/16/2023
感谢您的回复。我试图通过 yum 和 dnf 安装 libvirt-devel 并得到一个打包未找到错误。我正在编写一个与 libvirt 交互的 python 脚本,因此我需要在 python 脚本中导入 libvirt-python 包。我已经安装了python3-libvirt。

答: 暂无答案