tkinter cannot find the tk attribute - python-3.x

from another answer about tkinter issues I have tried the following code:
import tkinter
tkinter._test()
to which i get the error msg:
Traceback (most recent call last):
File "C:\Users\mickh\Dropbox\python code\helloWorld\GUI.py", line 1, in <module>
import tkinter
File "C:\Users\mickh\Dropbox\python code\helloWorld\tkinter.py", line 13, in <module>
root = tkinter.tk()
AttributeError: partially initialized module 'tkinter' has no attribute 'tk' (most likely due to a circular import).
My python version is 3.9.7 on windows 11
Also, the error msg says that the module is partially initialized. What does this mean?
I have looked at other answers to this question by I don't understand them

You have a file named tkinter.py in your project folder. When you do import tkinter in your code, python will import that file rather than the installed tkinter module.
The solution is to rename tkinter.py to something else.

Related

ImportError: cannot import name 'cpyHook' from partially initialized module 'pyWinhook'

This has been plaguing me for a while now, and I'm not sure what to do about it. I've tried modifying the init.py pyWinhook script's imports, but to no avail. Here's the whole error:
Traceback (most recent call last):
File "d:\myuser\Documents\Python\evil_programs\keylogger.py", line 6, in <module>
import pyWinhook as pyHook
File "C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\__init__.py", line 1, in <module>
from .HookManager import *
File "C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\HookManager.py", line 1, in <module>
from . import cpyHook
ImportError: cannot import name 'cpyHook' from partially initialized module 'pyWinhook' (most likely due to a circular import) (C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\__init__.py)
Thanks in advance
The way I fixed this is by installing Python 3.8.
Python 3.10 and 3.11 produced this issue.
I got this idea from the executable name on GitHub "pyWinhook-1.6.2.win-amd64-py3.8.exe"
Why it does not work with newer python, I have no clue.

my-voice-analysis myspsolution module not found error

we are using python library my-voice-analysis but getting myspsolution import error please tell what is the solution
import myspsolution as mysp
p="Audio" # Audio File title
c=r"speech.wav"
mysp.myspgend(p,c)
Traceback (most recent call last):
File "C:\Users\ADITYA\AppData\Local\Programs\Python\Python36\sp.py", line 1, in <module>
import myspsolution as mysp
ModuleNotFoundError: No module named 'myspsolution'
i know its a bit late and you probs dont need it anymore but
replace
import myspsolution as mysp
with
mysp=__import__("my-voice-analysis")

PyQt5 import Error

I am trying to create a GUI that I can all it from the terminal (Ubuntu here). The problem is, whenever I try to run the code from the terminal, I get the following message:
Traceback (most recent call last):
File "alert.pyw", line 3, in <module>
from PyQt5.QtCore import *
ImportError: No module named 'PyQt5'
The problem is: I only get this message when I try to call the program from the terminal using
python3 alert.pyw Hello
PyQt5 is installed and when I import it from the shell it (apparently) works fine...

Pygame import error

I am using pygame 1.9.2pre with python3. When I run idle3 and type
>>> import pygame
>>> pygame.init()
this works perfectly however when I write these two lines in a .py file and then run it in idle3 (by opening it and hitting F5) I get this messege
Traceback (most recent call last):
File "/home/nabeel/Devalopment/Python/pygame.py", line 6, in <module>
import pygame
File "/home/nabeel/Devalopment/Python/pygame.py", line 9, in <module>
pygame.init()
AttributeError: 'module' object has no attribute 'init'
Name your file something different from pygame.py otherwise your program will default to importing your own file and obviously that is not what you want since you want the other module.
You can use print(pygame.__path__) to check where it is that you are actually getting your pygame module from and in your case it would point to the directory you are currently in.

import tkinter yields error

Starting the Open Book on Python 3.1
import turtle #this yields an error from importing tkinter
Script:
import tkinter
exit()
Yields:
Traceback (most recent call last):
File "imptk.py", line 1, in <module>
import tkinter
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/__init__.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/lib-dynload/_tkinter.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/lib-dynload/_tkinter.so: mach-o, but wrong architecture
Any suggestions?
Your Python is incorrectly installed, the library in question has been compiled for the wrong architecture, maybe the wrong processor or for 32 bit when it should have been 64, or similar. In any case this is not a programming error.

Resources