For a little project of mine in Python, I want to use tkinter. But despite my efforts I can’t seem to make tkinter work with my interpreter. I am using uv to manage my environment.
I have done this kind of install in my home.nix :
home.packages = with pkgs; [
uv
tk
(python313.withPackages (ps: [ ps.tkinter ]))
home.sessionVariables = { UV_PYTHON = "${pkgs.python313.withPackages (ps: [ ps.tkinter ])}/bin/python3"; UV_PYTHON_PREFERENCE = "only-system"; # empêche uv de télécharger son propre Python UV_PYTHON_DOWNLOADS = "never";
and here is the error i get when i run uv run main.py
Traceback (most recent call last):
File “/home/user/projects//main.py”, line 2, in
import tkinter
File “/etc/profiles/per-user/user/lib/python3.13/tkinter/init.py”, line 38, in
import _tkinter # If this fails your Python may not be configured for Tk
^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named ‘_tkinter’
my system and nix version, i have enabled unstable :
26.05.20260409.4c1018d (Yarara)
nix (Nix) 2.31.4
I would be happy to know what I can do to fix this situation. I read about creating a shell.nix but it seems really overkill for what I want to do — I wanted to know if the approach I am using is possible at all.