On wheezy apt packaging python3-tk requires python3.2 & python3 packages. I want python 3.4 and have built it manually. The trouble is I don't know how to get my manual 3.4 build to 'see' the python3-tk install - when trying to import tkinter I get:

Traceback (most recent call last):
  File "/myscript.py", line 9, in <module>
    import tkinter as tk
  File "/opt/python3/lib/python3.4/tkinter/__init__.py", line 38, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'

if I start the system python3 interpreter and import tkinter it will load the module. I have my 3.4 manual build installed to a dir in /opt/. How do I get it to see the apt-installed tkinter?

  • By manual I assume you mean a local intallation frm source. I recommend backporting python 3.4 from testing/unstable. This will (probably) solve all your problems, if you are willing to learn something new. See unix.stackexchange.com/q/112157 for further information. This question is also listed in the backports tag. If you have further questions or need assistance, ask. Sep 10, 2014 at 21:10
  • I assume it's better to take from testing rather than unstable? Sep 11, 2014 at 9:05
  • No, there is no difference. I generally use the most recent version, which is in unstable by definition. Sometimes testing and unstable have the same version, of course. Sep 11, 2014 at 9:21

1 Answer 1


My guess is that you will need to change and environment variable, specifically environment, specifically PYTHONPATH before you run 'apt-get'.

But we need more details here. Specifically what is important is the value of sys.path. So do this. Go into the python3 shell that works and run import sys; print(sys.path). Set PYTHONPATH before you run apt-get to the corresponding value printing. For example if the result is:

['', '/usr/local/lib/python3.4/dist-packages/pyficache-0.2.6-py3.4.egg']

The equivalent would be

PYTHONPATH = ":/usr/local/lib/python3.4/dist-packages/pyficache-0.2.6-py3.4.egg"


PYTHONPATH=":/usr/local/lib/python3.4/dist-packages/pyficache-0.2.6-py3.4.egg" apt-get install ...

To understand what's missing, before line 38 of of /opt/python3/lib/python3.4/tkinter/__init__.py add a import sys; print(sys.path). And compare the with the value that works. Specifically you should be able to find the right directory.

As a last resort hack, you could change the print statement added to __init__.py add the directory, but I'd only do that if you are pressed for time (which probably isn't the case if you are asking on StackOverflow) or are totally frustrated and setting the environment variable doesn't work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .