11

I got a pretty confusing Problem:

I build a python program using tkinter. Then I dist-upgraded my ubuntu 13.10 (amd64) to ubuntu 14.04 LTS, now I tried to run my tkinter program. My compiler told me

ImportError: No module named tkinter

(The same with Tkinter or tk/Tk) Then I tried to reinstall tkinter using pip:

$ pip install tkinter


Could not find any downloads that satisfy the requirement tkinter
   Cleaning up...
   No distributions at all found for tkinter

again the same with Tkinter, tkinter, tk and Tk

So what happened? Have I got to run something like

$ pip update

(because tk is not anymore in the pip-repository) But why is it not installed anymore on my pc?

Edit: 1. I do not have no root access 2. in the pip.log is

>

  Downloading/unpacking tk   Getting page
> https://pypi.python.org/simple/tk/   Could not fetch URL
> https://pypi.python.org/simple/tk/: 404 Client Error: Not Found   Will
> skip URL https://pypi.python.org/simple/tk/ when looking for download
> links for tk   Getting page https://pypi.python.org/simple/   URLs to
> search for versions for tk:   * https://pypi.python.org/simple/tk/  
> Getting page https://pypi.python.org/simple/tk/   Could not fetch URL
> https://pypi.python.org/simple/tk/: 404 Client Error: Not Found   Will
> skip URL https://pypi.python.org/simple/tk/ when looking for download
> links for tk   Could not find any downloads that satisfy the
> requirement tk

something pretty close happened when I tried To install something using apt on my RaspberryPi without running

$ apt-get update

for a few months

I'd be glad for some help.

15

Try this:

sudo apt-get install python-tk

or, since your question is tagged as python3, this:

sudo apt-get install python3-tk
  • 1
    I tried( on a RaspberryPi) did not work. – LittleByBlue Jul 31 '14 at 18:33
  • 3
    Didn't work as in... – ElefantPhace Jul 31 '14 at 18:37
  • I tried running it on my Raspberry Pi and It didn't work – LittleByBlue Jul 31 '14 at 18:41
  • 2
    I got that much of. How did it not work? Any errors? What? – ElefantPhace Jul 31 '14 at 18:42
  • 1
    You sure you're running Ubuntu 14.04? Have you updated your sources? It's available on my machine – ElefantPhace Jul 31 '14 at 18:46
8

Of course You (I) can not install python-tk using pip!

As tk is TkInter (-> Interface to TK, which is written in C(++) ) you need to install the C(++) Library TK.

you cannot install this library using pip, as pip is designed to install (mainly)[1]pure python packages. By the way you would not have the sufficient rights to install the library. So you need to ask your superuser for help.

The only way to install it is using

sudo apt-get install python-tk # python2

or

sudo apt-get install python3-tk #python3

And last but not least you would have to use pip3 to install packages for python3.

It is the same as you cannot install freetype using pip.

Note: it is better to use python3 -m pip instead of pip3, as there might be multiple python3 installations on your machine (e.g. python3.4 and python3.5.1)

[1]: Actually pip is able to compile C/C++ Libraries, but it does not seem like it is able to install System-Libraries. Or one will create this package in future.

  • So Tkinter can not be installed via pip. Does this mean, the program which uses Tkinter, can not use virtualenv ? – tilaprimera Apr 25 '16 at 11:39
  • 1
    virtualenv and virtualenvwrapper ( you should use virtualenvwrapper) are able to use system packages, so you can use tk, but no custom tk installtion in your vitualenv. – LittleByBlue Apr 30 '16 at 7:51
  • Shouldn't there be a way with Python's Wheel package manager to install the binary packages like this one? – Huge May 24 '16 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.