Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Python installed via Homebrew not include Tkinter

I've installed Python via Homebrew on my Mac.

brew install python 

After that I checked my Python version as 2.7.11, then I tried to perform

import Tkinter 

I got following error message:

Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>     import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter 
like image 386
Daniel Chen Avatar asked Apr 21 '16 05:04

Daniel Chen


People also ask

Is Tkinter part of Python standard library?

Tkinter is the de facto way in Python to create Graphical User interfaces (GUIs) and is included in all standard Python Distributions. In fact, it's the only framework built into the Python standard library.

Is Tkinter pre installed in Python?

Tkinter comes pre-installed with the Python installer binaries for Mac OS X and the Windows platform. So if you install Python from the official binaries for Mac OS X or Windows platform, you are good to go with Tkinter. For Debian versions of Linux you have to install it manually by using the following commands.

Is Tkinter a Python package?

The tkinter package (“Tk interface”) is the standard Python interface to the Tcl/Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, including macOS, as well as on Windows systems.


1 Answers

I am running MacOS Big Sur (11.2.3).

With python2, I have Tkinter built-in.

With python3, it has to be installed manually and it's very simple, just run:

$ brew install python-tk 

To run python2 in a terminal, execute python file.py.

To run python3 in a terminal, execute python3 file.py.

like image 61
sgon00 Avatar answered Oct 02 '22 15:10

sgon00