0

I was trying to run a program that I have been making and ran into a problem with tkinter not being installed, as when I try to run my script in pycharm I get this error: ImportError: No module named '_tkinter', pleaseinstall the python3-tk package`

So I searched on here and found a solution and entered these commands:

sudo apt-get install python-support
sudo update-python-modules -a

which didn't work so I tried:

sudo apt-get install python3-tk

which was tagged as the answer on this question but it threw this error at me:

E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

Being pretty new to linux and the terminal, I am completely clueless as to how to do this.

I am using python 3.5 and just want to install tkinter so I can run this script, also before anyone asks yes I have imported tkinter and not Tkinter.

  • show your import statement – Rk.. Dec 21 '15 at 15:49
  • you checked http://stackoverflow.com/questions/4783810/install-tkinter-for-python? – Rk.. Dec 21 '15 at 15:50
  • I checked out the answer for that and still get the same error –  Dec 21 '15 at 15:52
  • My import statement: `from tkinter import *` –  Dec 21 '15 at 15:52
  • Have you ran the `sudo dpkg` statement it tells you? You just run that from the same place you are doing `sudo apt-get` stuff. – OneCricketeer Dec 21 '15 at 16:12
  • I get this: `dpkg: error: dpkg status database is locked by another process` –  Dec 21 '15 at 17:03
  • Now if I try to run `sudo apt-get install python3-tk` I get this error: `E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?` –  Dec 21 '15 at 17:04
  • If you run `ps aux | grep apt` is there any output? – wpercy Dec 21 '15 at 20:44
  • You are running another instance of `apt`, which locks `/var/lib/dpkg/lock`. –  Dec 22 '15 at 10:38
  • @wilbur if I run that command you gave me I got this output: http://pastebin.com/K7dHAcWC –  Dec 22 '15 at 21:21
  • @pydev I don't understand, i've used apt before to install software so why doesn't it work now. –  Dec 22 '15 at 21:21

2 Answers2

2

sudo apt-get install python3-tk is the correct way to install tkinter for Python 3 on Linux. However, you interrupted apt while it was installing. To fix the errors, run the command the error message suggested and then install tkinter.

sudo dpkg --configure -a
sudo apt-get install python3-tk

Then you can add from tkinter import *, import tkinter as tk or import tkinter to the beginning of your program depending on how you want to use it. You may also be interested in installing idle-python3.4.

Next time you need to install something just open the software manager from Menu, search for the program and install it :-)

aq2
  • 309
  • 3
  • 4
-2

Well when all logic fails- panic. Look for the illogical. I found that I was not running Python 3. My text editor is Geany, and reverts everything to run its default, which was set at Python 2. That included #!.

So, change the defaults in Geany:

Build > Set build commands > then in the dialogs replace every instance of Python with Python3