tkinter no module found windows 10 - python

I am trying to run this code
from tkinter import *
master = Tk()
w = Canvas(master, width=40, height=60)
w.pack()
canvas_height=20
canvas_width=200
y = int(canvas_height / 2)
w.create_line(0, y, canvas_width, y )
mainloop()
and I get the error
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'tkinter'
Since tkinter is already present in python, I checked in the C:\Python38\Lib\site-packages to see if tkinter is already present but its not there, also I tried the following
Running python -m tkinter from the command line should open a window
demonstrating a simple Tk interface, letting you know that tkinter is
properly installed on your system, and also showing what version of
Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific
to that version
as mentioned on tkinter — Python interface to Tcl/Tk
I tried to install the tkinter using pip3 install tk , and I got Requirement already satisfied: tk in c:\python38\Lib\site-packages (0.1.0)
But when I run the code again I get the error
ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none) ERROR: No matching distribution found for tkinter
My python version is Python 3.8.0 and pip version is pip 19.3.1
I have referred to this but no success.
Where am I going wrong? Please help

You may not have ticked tkinter during installation.
Download the latest version of python from python.org
Run the installer
Click modify
Select the Tk checkbox (and anything else you want)
And continue through the installation.
Done.

Related

Why cant I use my newly downloaded python library?

So ive tried to install customtkinter and the installation was successfull
Using cached customtkinter-4.6.3-py3-none-any.whl (246 kB)
Requirement already satisfied: darkdetect in c:\users\omen1\appdata\local\programs\python\python311\lib\site-packages (from customtkinter) (0.7.1)
Installing collected packages: customtkinter
Successfully installed customtkinter-4.6.3
But when i then go to vs code and write import customtkinter and run it says
Traceback (most recent call last):
File "c:\Users\OMEN1\OneDrive\Skrivbord\python projects\database.py", line 290, in <module>
import customtkinter
ModuleNotFoundError: No module named 'customtkinter'
I have tried to uninstall and re-install
My pip is also fully uppdated aswell as my python 3.11
Ive tried multiple things
Ensure that the interpreter you're using in VSCode is aligned to where you installed the library.
For example if you installed it with Python3, your VSCode may be pointed to Python2 instead.
Additionally, according to the PyPi link for that library - "To use CustomTkinter, just place the /customtkinter folder from this repository next to your program, and then you can do import customtkinter."

Why I can't use tkinter

I use Ubuntu. When I try to install tkinter it throws error
ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none)
ERROR: No matching distribution found for tkinter
I saw that this error is beacuse I already have tkinter, but when I try to import it there is another error
ModuleNotFoundError: No module named 'tkinter'
This happens also when I use capital T (Tkinter).
For installing tkinter in Ubuntu I use the command:
sudo apt install python3-tk

install tkinter for python 3.7.3 in Ubuntu 18.04

When I import tinker in python 3.7.3 on Ubuntu 18.04:
>>> import tkinter
I got:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
Then I install tk using both of the following:
sudo apt-get install python3-tk
It didn't work.
I also did all the things in Tkinter module not found on Ubuntu, still didn't work.
I noticed that when I do:
sudo apt-get install python3.7-tk
It says:
Note, selecting 'python3-tk' instead of 'python3.7-tk'
python3-tk is already the newest version (3.6.9-1~18.04).
Is tk automatically installed under python 3.6.9? How can I fix this?
I also saw a solution from https://wiki.python.org/moin/TkInter:
If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do not edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.
Could someone explain to do how to do the steps mentioned in this paragraph?
OK. I think the problem is that the newest version of tkinter for Ubuntu 18.04 is "python3-tk_3.6.9-1~18.04_i386.deb". Now I found that tk for python3.7.3 is available for other systems(e.g. python3-tk_3.7.3-1_amd64.deb). Can I download and use these ones on my system?
acw1668: Thanks this helped me a lot. I'm using Python 3.8. Using your method was able find where tkinter for Python 3.8 was install (/usr/lib/python3.8/). So i copied the files to (/usr/local/lib/python3.8/) which is where Python is installed on my computer. Now it'e working.

No module name _tkinter error while tkinter is installed

When trying to run my python 3 program that uses matplotlib via the command line, I get the following error:
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
The same happens when simply inputting:
>>>import tkinter
Suggested fixes such as installing python3-tk, python3.5-tk or python3.6-tk do not work, the result is:
python3.6-tk is already the newest version (3.6.6-1+xenial1).
and using matplotlib.use('agg') does not work as I need to output figures:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
with pip install tkinter, python-tk or python3-tk the result is :
Could not find a version that satisfies the requirement python3-tk (from versions: )
No matching distribution found for python3-tk
I also tried updating and reinstalling python3 but nothing seems to work (version 3.6.4). Could it be that python-tk is version 3.6.6 and my python 3.6.4?
Is there any other method I can try?

How to use the tkinter module on macOsSierra

I'm trying to learn how to use tkinter module in Python yet when I run it locally I get the following error :
Traceback (most recent call last):
File "emailer", line 1, in <module>
from tkinter import messagebox
ImportError: No module named tkinter
I've tried pip install tkinterand sudo pip install tkinter which throws the following error :
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
And finally when running which python in the terminal the output is /usr/bin/python
If you are using Python from a python.org 64-bit/32-bit Python
installer for Mac OS X 10.6 and later, you should only use IDLE or
tkinter with an updated third-party Tcl/Tk 8.5 (not 8.6), like
ActiveTcl 8.5 installed.
If you are using Mac OS X 10.6, do not use IDLE or Tkinter from the
Apple-supplied Python 2.6.1 in Mac OS X 10.6. If possible, install and
use a newer version of Python and of Tcl/Tk.
If you are using Mac OS X 10.7 or later, the Apple-supplied Tcl/Tk 8.5
still has serious bugs that can cause application crashes. If you wish
to use IDLE or Tkinter, install and use a newer version of Python and
of Tcl/Tk.
Actually you can use homebrew:
brew install tcl-tk
brew link tcl-tk --force
Have a look at tcltk.

Categories