Import Error: No Module named 'Tkinter' [duplicate] - python

This question already has answers here:
ImportError: No module named 'Tkinter'
(27 answers)
Closed 5 years ago.
I am trying to create a simple gui and run in IDLE but every time I run it , it gives me the error :Import Error: No module named 'Tkinter'
This is my code if anybody is wondering:
from Tkinter import *
root = Tk()
root.mainloop()
I have also tried to verify if i have installed tkinter or not with command import tkinter and tkinter._test() and it shows that I have tkinter installed.

Use lowercase T for tkinter import statement for Python 3 :
import tkinter
IF your using python2 it's:
from Tkinter import *
But your using python3, so it's:
from tkinter import *

Related

Restoring my tkinter project to funtionality

I was working on my project and everything was working perfectly. Suddenly the interpreter is giving the error
from tkinter import _flattern, _join, _stringify, _splitdict
ImportError:cannot import name '_flattern', from 'tkinter' (path to my
file directory)
All of my program files from all projects that i am using tkinter are showing the same error

Pyinstaller - ModuleNotFoundError: No module named 'cpuinfo' [duplicate]

This question already has answers here:
Pyinstaller 'failed to execute' script
(2 answers)
Processes stuck in loop with PyInstaller-executable
(1 answer)
Closed 20 days ago.
I'm trying to package this script but I keep getting this error message
Traceback (most recent call last):
File "systeminfo.py", line 1, in <module>
ModuleNotFoundError: No module named 'cpuinfo'
[6308] Failed to execute script systeminfo
I tried this into cmd
pyinstaller -F --hidden-import="cpuinfo" systeminfo.py
I'm on the latest version of pyinstaller and pip.
This is the import section of my file:
import psutil, platform, GPUtil, cpuinfo, os, sys, wmi, winreg, getpass
from tabulate import tabulate
from datetime import datetime
When I run it, it just opens up and closes out. But when I run it through CMD, that's when I get that error message.
How do I fix this? I want to include all the modules so I can run this script on different computers that don't have python installed.
EDIT:
I fixed this issue by using this thread: Pyinstaller 'failed to execute' script
I use pycharm so this worked for me.
The only issue is whenever the CMD opens up, nothing happens. The only thing that can printed is if I hardcode a print(). Functions aren't working at all.
fix it with :
pip install py-cpuinfo

How can I generate the exe application from python file [duplicate]

This question already has answers here:
How to install python application with tkcalendar module by pyinstaller?
(3 answers)
Closed 3 years ago.
I'm trying to get the .exe file from this script using pyinstaller
I used this command pyinstaller -w -F test.py while I'm in the test directory
the file test.py contains
from tkinter import *
from tkcalendar import DateEntry
root = Tk()
date = DateEntry(root, year=2001, month=11, day=11, width=17,)
date.pack()
root.mainloop()
The .exe file that I get is not WORKING?
when I do this pyinstaller -F test.py I get the error of no module named babel.numbers on the console
It seems that PyInstaller can't resolve module babel.numbers for tkcalendar. One easy way is to use hidden-import:
pyinstaller -F --hidden-import "babel.numbers" test.py

TkMessageBox - No Module

import TkMessageBox
When I import TkMessageBox it displays the messsge 'ImportError: No module named 'TkMessageBox'.
As far as I know im using python 3.3.2 and Tk 8.5.
Am I using the wrong version of python or importing it wrong ?
Any answers would be extremely useful. Alternatively is there something similar in the version i am using?
In Python3.x things have changed a little bit:
>>> import tkinter
>>> import tkinter.messagebox
>>>
I mean what we call tkMessageBox in Python2.x becomes tkinter.messagebox in Python3.x
If you don't want to have to change the code for Python 2 vs Python 3, you can use import as:
try:
from tkinter import messagebox
except ImportError:
# Python 2
import tkMessageBox as messagebox
:edit:
However, tkinter is in a separate package in Debian due to Debian policies, so to avoid an incorrect fallback to Python 2 code I now use:
import sys
if sys.version_info.major >= 3:
from tkinter import messagebox
else:
import tkMessageBox as messagebox
Then using messagebox as follows will work in either version:
messagebox.showerror("Error", "Message.")
In Python 2.x, to import, you'd say import tkMessageBox. But in Python 3.x, it's been renamed to import tkinter.messagebox.
Hope it helped :))
for python 3.x
import tkinter
import tkinter.messagebox
from tkinter import messagebox sous Python 3
messagebox.showinfo(title=None, message=None, **options)

Windows Python 2.7 wxwidgets and 'gizmos'

Can anyone give me precise instructions on how to access the wx 'gizmos' module?
import wx.gizmos
ImportError: No module named gizmos
The code in question has this:
import wx
import string
import wx.gizmos
from wx.lib.mixins import treemixin
import Descriptor
'pip list' reports
wxPython-Phoenix (3.0.3.dev1830+0b5f910)
Do I have the right package installed? I should add that these files are present:
\python27\Lib\wxpython\wx-3.0-msw\wx\gizmos.py
\python27\Lib\wxpython\wx-3.0-msw\wx\_gizmos.pyd
[edit] For clarification, this seems to be OK so I'm reasonably sure the WX module is installed correctly.
import wx
import copy
# had to add .agw to get this to load
import wx.lib.agw.customtreectrl as CT
import DescriptorDetailsPanel
TAIA
Congrats, you have two installs of wx. You can use pkg_resources to get the one you want. Put the following at the top of the script:
__requires__ = ["wx >= 3.0"]
import pkg_resources
This will tell pkg_resources to set things up so that a version of wx of at least 3.0 will be available if you import wx rather than the default 2.x.
You can try to remove wxpython from pip install and reinstall wxpython from this site:
https://www.wxpython.org/download.php
It worked for me!

Categories