How do i install Tkinter i watched tutorials but it doesnt match mine python 3.10
Videos
It is not very easy to install Tkinter locally to use with system-provided Python. You may build it from sources, but this is usually not the best idea with a binary package-based distro you're apparently running.
It's safer to apt-get install python3-tk on your machine(s).
(Works on Debian-derived distributions like for Ubuntu; refer to your package manager and package list on other distributions.)
Actually, you just need to use the following to install the tkinter for python3:
sudo apt-get install python3-tk
In addition, for Fedora users, use the following command:
sudo dnf install python3-tkinter
If you installed python3.8 using apt (via ppa:deadsnakes/ppa), it can be installed using apt too, the name of library is python3.8-tk.
sudo apt install python3.8-tk
In my case, it solves the problem. For instance, now I can use matplotlib in python3.8 which requires tkinter.
Recompile and reinstall python3.8 specifying path to folders with tcl, tk includes and libraries.
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev python-tk python3-tk tk-dev
cd ~/Downloads
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
tar -xvf Python-3.8.2.tgz
cd Python-3.8.2
Edit ./configure file the next way: replace ... for next lines:
--with-tcltk-includes='-I/usr/include'
--with-tcltk-libs='-L/usr/lib'
./configure
make -j2 # replace 2 by number of processor cores you have
sudo make install
$ python3.8
Python 3.8.2 (default, May 11 2020, 14:30:03)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
Python 3.8 installed through apt and pyenv on 16.04 does not include tkinter, as I think or there's a some bug that does not allow to import it. Only rebuilding helped. Previously I've used 20.04 with built in Python 3.8 version, which supports tkinter with only additional packages installing as it is for Python 3.5 on 16.04.
python3.8-tk installation as Ankur A Sharma said is also required. I've forget to mention it. But it is not sufficient for 16.04, at least in my case.
Additional requirement from OP's comment:
sudo ./configure --with-tcltk-includes='-I/usr/include -I/usr/include/tcl' --with-tcltk-libs='-L/usr/lib -ltcl -ltk' --enable-optimizations
sudo apt-get install python3-tk Installs tkinter for Python3.x.x
Sources:
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;
sudo apt-get install python3.6-tk
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.
sudo apt install python3.x-tk
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;
sudo add-apt-repository ppa:deadsnakes/ppa