[Python] Problems with Tkinter libraries dependencies in a codespace on Ubuntu 22.04.1 (linux)

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    Issue with Testing tkinter in a Headless Environment

    What I Am Trying to Do


    I am trying to test if tkinter is installed and working by running the following command in the terminal:

    python3 -m tkinter


    I've installed tkinter dependencies (e.g., sudo apt-get install python3-tk) and verified your Python version is 3.1

    Error Message When I run the command, I get the following error:

    File "<frozen runpy>", line 198, in _run_module_as_main
    File "<frozen runpy>", line 88, in _run_code
    File "/home/codespace/.python/current/lib/python3.12/tkinter/__main__.py", line 7, in <module>
    main()
    File "/home/codespace/.python/current/lib/python3.12/tkinter/__init__.py", line 4633, in _test
    root = Tk()
    ^^^^
    File "/home/codespace/.python/current/lib/python3.12/tkinter/__init__.py", line 2340, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    _tkinter.TclError: no display name and no $DISPLAY environment variable

    Continue reading...

Compartilhe esta Página