Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python not configured for Tk

Tags:

I am using Ubuntu 13.10 and Python 3.3.4 using pyenv. I have no problem using other modules. When I enter python console and write

import tkinter 

It outputs

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/serdar/.pyenv/versions/3.3.4/lib/python3.3/tkinter/__init__.py", line 40, in <module> import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named '_tkinter' 

I already installed python3-tk and tk-devel.

like image 445
serdar Avatar asked Mar 21 '14 04:03

serdar


People also ask

How do I install Python Tk?

The simplest method to install Tkinter in a Windows environment is to download and install either ActivePython 3.8 or 3.7 from here. Alternatively, you can create and activate a Conda environment with Python 3.7 or greater that is integrated with the latest version of Tkinter.

Why Tkinter is not working in Python?

The easiest way to fix this problem is by upgrading your python to use python 3. If upgrading python is not an option, you only need to rename your imports to use Tkinter (uppercase) instead of tkinter (lowercase). Output: As a result, this window proves that your python installation includes the Tkinter module.


2 Answers

You need to have the Tk development files/headers available during pyenv install.

On Ubuntu (15.04) the following should provide them: sudo apt-get install tk-dev.

After this, pyenv install 3.4.3 (or pyenv install 2.7.10 etc) should pick it up and have support for Tk.

(Reference issue in pyenv)

like image 160
blueyed Avatar answered Sep 19 '22 11:09

blueyed


This is a guide for Mac users,

  1. Uninstall your python version. For example: pyenv uninstall 3.7.2
  2. Install TK: brew install tcl-tk
  3. Follow the post install steps and config tk:
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib" export CPPFLAGS="-I/usr/local/opt/tcl-tk/include" export PATH=$PATH:/usr/local/opt/tcl-tk/bin 
  1. Reload your terminal session and make sure all settings above are correctly set
  2. Install python: pyenv install 3.7.2

The TK should work now

like image 28
dpaluy Avatar answered Sep 23 '22 11:09

dpaluy