How to use tkinter in python on nixos (fhs)?

I struggle using Python with tkinter (should be in the standard lib) in nixos. I tried out different thing like according to this side install tkinter as package…

Here is me shell.nix:

{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
  name = "tkinter test";
  targetPkgs = pkgs: (with pkgs; [
    python310
    python310Packages.pip
    python310Packages.tkinter
    tk
  ]);
  runScript = "bash";
}).env

Here is the error i still get:

$ python -m tkinter
Traceback (most recent call last):
  File "/nix/store/sgrlfqraqa3jhpdg2qwbbggs59dx03ky-python3-3.10.13/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/nix/store/sgrlfqraqa3jhpdg2qwbbggs59dx03ky-python3-3.10.13/lib/python3.10/runpy.py", line 146, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/nix/store/sgrlfqraqa3jhpdg2qwbbggs59dx03ky-python3-3.10.13/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/nix/store/sgrlfqraqa3jhpdg2qwbbggs59dx03ky-python3-3.10.13/lib/python3.10/tkinter/__init__.py", line 37, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

Does anybody know how to solve this? Thanks in advance

Ok, solved it by using python310Full instead of just python310. I will leave this post for others who have the same problem.

3 Likes