ImportError: No module named 'Tkinter'' - python

Looking at this link, when I install Python it says Tcl/Tk/Tkinter will also install, but when I run a game in Python, I get an import error. I have my usual import statements as well, but it's still not working. I also looked at this very similar problem, but the answer isn't working for me.
import simplegui
import random
from tkinter import *

Assuming you are using Python 3.x, programs must be run with python3 my-program.py (not python my-program.py).

I am assuming you are using python2.
Try this
from Tkinter import *
You are putting wrong name for module. This will work.
EDIT AFTER COMMENT
For python3 install this python3-tk and your code will work.

Related

ModuleNotFoundError: No module named 'tkinter' after

I have been recently attempting to try out some minor game development with Python 3.9 and have been running into some problems. For some reason, Python does not recognize that I have tkinter installed.
From what I have seen online, a big fix is to make sure the path variables are set up correctly. I have already added it to my env variables but that has not seemed to fix anything.
I also know I have it installed, as I see it here in my Python site-packages folder.
At this point, I am stumped. I do have the import as tkinter as well and not Tkinter.
The only thing I can think of now is totally uninstalling Python but I would prefer not to do that if there are any other options.
Here is the code:
import math
import random
import pygame
import tkinter as tk
from tkinter import messagebox
class cube(object):
rows = 20
w = 500
I am using Windows 10 and VSCode as well.
Anything helps and thanks!
Seems I somehow screwed up my Python installation. Completely removing it from my system and reinstalling seemed to fix all of my issues.

Outdated hashlib module in a non-current version of Python

I installed a python package that I need, and tried to import it, but there's a line of code in the package:
from hashlib import blake2s
which returned the error:
ImportError: cannot import name 'blake2s'
After a bit of reading, I found that the hashlib module in Python 3.6+ has blake2s, but I'm using Python 3.5.6. Updating my Python version would solve this problem, but I don't have admin access on this system. So I'm stuck on Python 3.5.6.
Is there a way to get blake2s working in Python 3.5?
edit: I'm wondering if this can be used somehow...
https://github.com/dchest/pyblake2
Answering my own question...
I installed the pyblake2 package (linked in my edit above), then went inside the package I was trying to install and modified the import line.
I changed
from hashlib import blake2s
to
from pyblake2 import blake2s
and then reinstalled the package with that modified line.
It worked! The package is working in Python 3.5 even though Python 3.5 hashlib does not have blake2s.

No module named Tkinter error

I have been using http://python.codnex.net/index.php. I have tried to use Tkinter but it shows ImportError: No module named Tkinter on line 1
I have tried many things including:
import Tkinter
import tkinter
from tkinter import *
If you find something please let me know.
According to this question & answer in Quora you can't use tkinter with online interpreters. Though apparently you can run linux along chromeOS if you have non-school version.
I might be wrong, but I believe it's because tkinter is a GUI module, which can't be ran from a webbrowser.
Have you tried importing it in a local python instance?
it wont work on web browser ,Run a local python instance and import tkinter after installing tkinter by using command prompt using the command pip install python-tk

How to import pygame, pyperclip?

I am fairly new to python but am having issues importing certain packages within my code. I try to import pyperclip aswell as pygame. I've installed them both manually and I've tried importing them using import pygame and import pyperclip and I get
"no module named 'pyperclip'"
and the same thing for pygame. I've tried opening by putting just import pygame and saved it to run it in the interactive shell and I've also just tried typing it into the interactive shell.
I'm running linux mint 17.3 and python 2.7.6
Has anyone else had this issue?
Any help would be appreciated. Za
I had the same problem. I am also new to Python and programming. I tried about 100 things, but what worked for me was typing the following in the command shell:
pip install pyperclip
That was it. However, I was using Windows' command module, so. . . you know. But it's worth a shot!
This link might help, too (it has Linux instructions, etc): https://github.com/asweigart/pyperclip

Cannot import scitools using Anaconda-Python

I am trying to install scitools with the hope of being able to use Easyviz. I installed scitools for windows as suggested in the first link. However, when I type from scitools.std import * into python I get the following error message:
ImportError: No module named oldnumeric.mlab
numpy import failed!
see doc of scitools.numpytools module for how to choose Numeric instead
This was discussed here and categorized as fixed, however I don't see how I can make this work or how to fix it. Is there something I am supposed to do to make this work?
I encountered the same issue on Ubuntu 16.04 LTS. However, such issue was not found on Trisquel GNU Linux.
The solution which I found by randomly testing was -
Do not import scitools. Just import numpy.
As an example if you were to write -
from scitools.std import *
simply do -
import numpy as np
and use numpy libraries. For plotting use matplotlib that will solve this issue.

Categories

Resources