I am new to Ubuntu and Linux in general.
I created a dual boot OS on my laptop (Windows 10 and Ubuntu).
- Typing:
sudo apt-get install python3-tk
(or evenpython-tk
) didn't work. - Trying to install the
python3-dev
orpython-devel
(no luck). - Downloading Tcl and Tk to manually install.
In Windows 10 Bash Subsystem the Tk and Tcl are already included, so I thought Ubuntu already had it. But, I want to use my Ubuntu desktop to develop Python GUI apps.
So, how can I install the Tcl/Tk to be use in Python 3.5 for GUI development?
I loaded Python 3.5.2 fine but need the GUI modules enabled.
The code to test that Tk is working is:
- Type
python3
Type:
import tkinter tkinter._test()
Result: a GUI pop-up displaying
This is a Tcl/Tk version..
sudo apt-get install python3-tk
Installstkinter
for Python3.x.xSources:
https://stackoverflow.com/questions/6084416/tkinter-module-not-found-on-ubuntu https://pythonprogramming.net/python-3-tkinter-basics-tutorial/
For a python 3.6 virtual environment with Python 3.5 as the "system" python (Ubuntu) , I had to install tk 3.6 to match;
My default python in ubuntu was 3.5, so when using a venv for 3.6, I would get an import error. Drove me crazy for a while.
[Edit: As this question ages]
In general, it seems if one is using a virtual environment with a python of a different version than that of ones base machine, one must install tk for the version of python used in the virtual environment.
Where 3.x would match the version of the virtual environment.
[Edit]
It may be necessary to add the repository for tk. In my experience, it was the same repository from which I pulled python3.6, but that may change with time;
In my case, I was getting the same error as "ImportError: No module named '_tkinter'" for python3.5 in-spite of doing the following things: - Installing python3-tk and tkinter-dev - Tkinter directory being available in /usr/lib/python3.5.
The observed error was from the following file:
However, when I simply ran the python from /usr/bin like /usr/bin/python3.5 from terminal, it worked for me!
In short, just ensure the python version being run from terminal has the tkinter installed and configured :)
I have Ubuntu16.04 installed on my system which comes with default python2.7 and python3.5
This might be interesting when installing from source (which most python users won't):
After installing tcl and tk.
Go back to your version of Python, do
make
. And, if multiple version ofpython
exist, do amake altinstall
.type:
results OK - pop GUI opened and working as expected.
Installing just library files may not work since you want to use library itself not develop it.
This worked for me: