想要在 NixOS 上使用 Gtk3 和 Python3

问题描述 投票:0回答:1

我想在 NixOS 上的 Python3 中使用 Gtk3。这个命令

nix-shell -p gobject-introspection gtk3 'python3.withPackages(ps : with ps; [ pygobject3 ])'

允许

import gi
在 nix-shell 内的 python3 环境中。这就是我尝试在 configuration.nix 文件中为 Python3 定义 Gtk 的方式。

  environment.systemPackages = with pkgs; [
    gtk3
    python3
    python3Packages.pygobject3
    python3Packages.pip
  ];

sudo nixos-rebuild switch
命令不会显示任何错误,但在python3环境中
import gi
会导致:

ModuleNotFoundError: No module named 'gi'

我需要改变什么?

这是 NixOs 的全新安装,带有 Cinnamon DE、Python 3.11.8、Gtk 3.24。

python gtk3 nixos
1个回答
0
投票

这就是我修改我的 configuration.nix 文件的方法,感谢 @CharlesDuffy 的评论。

  users.users.reb = {
    isNormalUser = true;
    description = "RB";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      firefox
      libreoffice-fresh
      vlc
      gtk3
      (python3.withPackages (subpkgs: with subpkgs; [
        pip
        pygobject3
      ]))
    #  thunderbird
    ];
  };
© www.soinside.com 2019 - 2024. All rights reserved.