Tkinter unable to configure - python

I have this problem when I try to run an app that imports turtle:
Traceback (most recent call last):
File "/home/panos/Documents/python/challenge_60.py", line 1, in <module>
import turtle
File "/usr/local/lib/python3.9/turtle.py", line 107, in <module>
import tkinter as TK
File "/usr/local/lib/python3.9/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
I have done the below commands:
sudo apt-get install python3-tk
pip3 install tkinter
pip3 install PythonTurtle
pip3 install Tcl
sudo apt-get install python-tk python3-tk tk-dev
sudo apt-get install python3-PythonTurtle
And, although it is installed, the error still exists. I haven't understand what does wiki says. Could you explain, with all the details, what do I have to do, because I am a newbie at Linux and commands in general?

This error is probably made, because you have installed the tkinter , for instance, on python 3.7, but you are running your code with an interpreter based on python 3.8.
Another reasons, like installing the library in a virtual environment and trying to run the code out of the venv, can also
lead to this error.
Make sure pip and python command are in the same location/path
to make sure they are from the same SDK.
This command indicates where python is installed on your machine:
(Unix Only)
which python
Windows users, use this snippet below to find path of the installed python :
import sys
locate_python = sys.exec_prefix
print(locate_python)
Check the pip location using the which command as well.
which pip
If pip and python are in the same path, you probably won't get the error anymore.

First you have to pay attention to a few things 1- All the packs must be updated and installed If you have downloaded the packs, update them, especially the pip module that is for installation 2- Note that the spelling of the words you use is correct 3 - Maybe the code you write does not support that module, you should also pay attention to this issue 4- Finally, there are some problems in your code. First, to download the Tkinter module, you have to write pip3 install tk or pip install tk. You should not write the word Tkinter yourself. Update the latest version and then try again. If it still does not work, turn on your Windows 10 (if not) and finally the last solution is to change your ide vs code. The best ide for this situation. Is And you can also help to install and import the library of online articles. If you use pycharm, enter the Windows command line and type pip3 install future or pip install future, and then the thinner will be imported for you, and then enter the following command: from future.moves import tkinter and you can find how to install each house in different ideas with a simple search

Related

Pyautogui could not be resolved [duplicate]

I have read import error for pyautogui
and this did not answer my question.
I am trying to import pyautogui via the 3.5.2 shell or windows cmd. but when using the shell for:
import pyautogui
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pyautogui
ImportError: No module named 'pyautogui'
I have seen people say they resolved by using 3.5 but not for me. I have also seen people say that uninstalling and reinstalling can fix issues. I did this and on reinstall made sure that the path option was selected.
Step one: open windows cmd
Step two: and type in py -3.8 -m pip install pyautogui
You will most likely get a message that says: pip is not up to date, it would look like this: https://i.stack.imgur.com/DOfzQ.png
if you get this error Type in: py -m pip install --upgrade pip
Step three: Open: https://bootstrap.pypa.io/get-pip.py and copy everything on this page
Step four: Open IDLE and run what you just copied
Step five: Open windows cmd again and try py -3.8 -m pip install pyautogui again
Step six: Now try to run it again.
if this doesnt work please show us the errors you get.
Check that you are installing the package using the correct Python Version, in the documentation says that you have to install correspondant to your python version. In my case, I fixed it using python 3.9 (and making sure that my intepreter in VSC is set to Python 3.9.1)
Try doing pip install pyautogui and if it says all requirements are satisfied type in pip show pyautogui and if it shows then just try restarting your IDE and it should work

import _tkinter # If this fails your Python may not be configured for Tk error in python 3.8

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.

ModuleNotFoundError: No module named 'pynput' Python3 and pip3

I want to use 'pynput', so I used pip to add it to my environment.
The installation proceeds without problem.
But I am unable to import it into my project.
I am using python 3.8.1 on my environment.
I used pip3 for installation.
I have already tried to install pynput, uninstall it and reinstall it multiple times.
My .py file doesn't have a confusing name like "pynput.py"
I am comfortable with my environment when I try to execute my file.
I am trying to run from my terminal or VSCodium, and neither of them works.
And I work on Debian 10.
pip freeze :
pynput==1.6.7
python-xlib==0.26
six==1.14.0
Traceback :
Traceback (most recent call last):
File "./play.py", line 6, in <module>
from pynput import keyboard
ModuleNotFoundError: No module named 'pynput'
So I don't understand why it doesn't work.
thank you in advance for your help :)
When creating my project, I was not working under an environment, so I used the classic shebang: #!/bin/python3.
Then, I went under an environment to use pynput, but I just forgot to change my shebang to #!/usr/bin/env python.
So, actually, I didn't risk finding pynput
It might be possible you have two versions. Rry installing with python3 -m pip install pynput or you should use some older version of Python. I am using 3.7.5 and its works perfect for me.
Try importing from the terminal.

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.

Unable to import pyautogui

I have read import error for pyautogui
and this did not answer my question.
I am trying to import pyautogui via the 3.5.2 shell or windows cmd. but when using the shell for:
import pyautogui
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pyautogui
ImportError: No module named 'pyautogui'
I have seen people say they resolved by using 3.5 but not for me. I have also seen people say that uninstalling and reinstalling can fix issues. I did this and on reinstall made sure that the path option was selected.
Step one: open windows cmd
Step two: and type in py -3.8 -m pip install pyautogui
You will most likely get a message that says: pip is not up to date, it would look like this: https://i.stack.imgur.com/DOfzQ.png
if you get this error Type in: py -m pip install --upgrade pip
Step three: Open: https://bootstrap.pypa.io/get-pip.py and copy everything on this page
Step four: Open IDLE and run what you just copied
Step five: Open windows cmd again and try py -3.8 -m pip install pyautogui again
Step six: Now try to run it again.
if this doesnt work please show us the errors you get.
Check that you are installing the package using the correct Python Version, in the documentation says that you have to install correspondant to your python version. In my case, I fixed it using python 3.9 (and making sure that my intepreter in VSC is set to Python 3.9.1)
Try doing pip install pyautogui and if it says all requirements are satisfied type in pip show pyautogui and if it shows then just try restarting your IDE and it should work

Categories