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.
Related
Currently using Ubuntu 20.04 LTS with python3.8.5.
Its my first time using ubuntu with absolutely no previous knowledge of terminal.SO,would love to have a detailed answer if possible.
Below is terminal output when i try importing tkinter in python3.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/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'
>>>
I have reinstalled python3 and tkinter using sudo apt.But still it shows same error.
When i run the same command in python IDLE it works without any error.
I hope this explains my problem clearly, if any other info. is required pls reply.
I also tried running the command >>>from tkinter import *
I faced the same issue on MacOS. I was using a Python virtual environment. This command worked for me:
brew install python-tk
CentOS 8 + Python 3.9.5
following are what i have doneļ¼
1st:
yum search tkinter
yum install python39-tkinter.x86_64
2nd:
yum install tk-devel
3rd: cd python3.9.5 source folder
make install
it work in my case
since I'm still using python 3.9, this code works for me:
brew install python-tk#3.9
if using brew install python-tk brew will install python-tk#3.10 which is key-only
I had the same issue. Switched from 3.8 to 3.7 and it worked. I'm using PyCharm CE, which makes it easy to switch between interpreters.
Resolved the issue it occurred because the Tkinter was installed for version 3.5 and not for the 3.8 version. For that, I installed the 3.5 version and kept only one version i.e. 3.8, and installed Tkinter again, and it worked!
This is just a workaround to make things work, but the more preferred way is to create a venv and then install the particular versions of python and libraries that are needed.
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.
In Ubuntu 15.10,Running
python3.4 sound.py
leads to this error:
Traceback (most recent call last):
File "sound.py", line 2, in <module>
import pyglet
ImportError: No module named 'pyglet'
I already installed pyglet with running this command:
sudo easy_install -U pyglet
resulting
Searching for pyglet
Reading https://pypi.python.org/simple/pyglet/
Best match: pyglet 1.2.4
Processing pyglet-1.2.4-py2.7.egg
pyglet 1.2.4 is already the active version in easy-install.pth
Using /usr/local/lib/python2.7/dist-packages/pyglet-1.2.4-py2.7.egg
Processing dependencies for pyglet
Finished processing dependencies for pyglet
I am confused about what is missing. I guess there are some confusion about different verions of python, pyglet or Ubuntu.
From the install output it seems that the installed version of pyglet goes to python 2.7 packages. From your command you are explicitly calling python 3.4 There might be a problem there. python 3.4 will not go to 2.7's packages to check for the module.
I suggest that you call the script using python 2.7. running just python is enough (the default env python)
You can take a look at this question on the installation of python 2 and 3 packages too
I have an existing Python 2.4 and it is working properly with tkinter as I tested it using
python
import _tkinter
import Tkinter
Tkinter._test()
Now, I have installed python 2.5.2 but when I try the same tests (with the newer version), it returns (but the same tests are working for the previous version)
ImportError: No module named _tkinter
I know that tcl8.5 and tk8.5 are installed on my machine as the following commands return there locations
whereis tcl
tcl: /usr/lib/tcl8.4 /usr/local/lib/tcl8.5 /usr/local/lib/tcl8.4 /usr/share/tcl8.4
whereis tk
tk: /usr/lib/tk8.4 /usr/local/lib/tk8.5 /usr/share/tk8.4
Any ideas how do I make my newer python version work with tkinter?
The files you found are for linking directly to tcl/tk. Python depends on another library as well: _tkinter.so. It should be in /usr/lib/python2.5/lib-dynload/_tkinter.so.
How did you install python2.5? If you are using Debian or Ubuntu you need to install the python-tk package to get Tkinter support.
If the _tkinter.so file is there, your environment could be causing problems.
If
python -E -c "import
Tkinter;Tkinter._test()"
suceeds, but
python -c "import
Tkinter;Tkinter._test()"
fails, then the problem is with how your environment is set up. Check the value of PYTHONPATH is set correctly.
I'm following a tutorial of making desktop apps. with python and qt4, I downloaded and installed qt creator ide, created the .ui file and then I had to convert it using pyuic4, I've been trying a lot of things and still can't do it.
I thought that pyuic4 would be installed with Qt creator IDE, but it seems that's not the case, so I installed pyqt through macports:
sudo port install py26-pyqt4
I didn't know but that came with qt, so it was about 3 hours building it.
after installing it I tried to convert the .ui again:
$ pyuic4-2.6 principal.ui -o prin.py
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/pyuic.py", line 4, in <module>
from PyQt4 import QtCore
ImportError: No module named PyQt4
No module named PyQt4? wasn't that what I just installed?
Thanks, and excuse me if my english isn't 100% good.
I've solved it, you have to use the python of macports instead of the default that comes with OS X, to do that install python_select through macports:
sudo port install python_select
sudo python_select python26
I made some notes on building and install PyQt4 on Mac Snow Leopard.
The order is important, and there are some quirks with 64-bit libraries. The default Mac Qt libs are Carbon (32 bit), whereas Mac system Python is 64 bit and needs the Cocoa libs.
I spent a while finding the package name in Homebrew. It seems to be:
brew install pyqt