import tkinter yields error - python-3.x

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.

Related

tkinter cannot find the tk attribute

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.

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.

ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

I have a simple python program which I am running on a Mac machine.
import numpy as np
def main():
print("np arr test")
arr = np.array([1.0, 2.0, 3.0])
print(arr)
if __name__ == "__main__":
main()
I've verified that the numpy library was correct installed through pip
pip3 list | grep numpy
msgpack-numpy 0.4.4.3
numpy 1.16.2
numpydoc 0.8.0
I get the following error when I run the program
Traceback (most recent call last):
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Volumes/workplace/RPAsosDevelopmentWS/src/RPAsosDevelopmentPy/src/rp_asos_development_py/adhoc_dev/float_nan_test.py", line 1, in <module>
import numpy as np
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/Volumes/brazil-pkg-cache/packages/Python-numpy/Python-numpy-1.x.140450.0/AL2012/DEV.STD.PTHREAD/build/lib/python3.6/site-packages/numpy/core/__init__.py", line 50, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.6 from "/usr/local/bin/python3.6"
* The NumPy version is: "1.18.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
Process finished with exit code 1
Can you please help me figure out what I am missing? Appreciate your response!
NOTE : Based on the stack overflow post I updated the numpy through the following command
pip3 install numpy --upgrade
pip3 list | grep numpy
msgpack-numpy 0.4.4.3
numpy 1.21.2
numpydoc 0.8.0
WARNING: You are using pip version 21.2.1; however, version 21.2.4 is available.
However I still see the error message
Try to uninstall numpy and install it again.

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")

Can't import cv2 in Python 2.7 linux

I'm trying to get OpenDroneMap to run on my linux mint machine. I've been working my way through a number of problems in the current release's dependency chain.
At the moment, I'm stumped on getting the OpenCV module, cv2 to import.
OpenCV is required by an OpenDroneMap dependency, OpenSfM and it's one of the OpenSfM py files that tries to import the module cv2.
Anyway, running OpenDroneMap generates the error:
Traceback (most recent call last):
File "~/OpenDroneMap/src/OpenSfM/bin/opensfm", line 10, in <module>
from opensfm import commands
File "~/OpenDroneMap/src/OpenSfM/opensfm/commands/__init__.py", line 3, in <module>
import extract_metadata
File "~/OpenDroneMap/src/OpenSfM/opensfm/commands/extract_metadata.py", line 5, in <module>
from opensfm import dataset
File "~/OpenDroneMap/src/OpenSfM/opensfm/dataset.py", line 12, in <module>
import cv2
ImportError: dynamic module does not define init function (PyInit_cv2)
b
quitting cause:
PYTHONPATH=~/OpenDroneMap/lib/python2.7/dist-packages "~/OpenDroneMap/src/OpenSfM/bin/run_all" opensfm
returned with code 256.
From what I can tell, the import error cause typically suggests that the cv2 module was not found. I've ensured that cv2.so does exist in the path specified, as well as the usr/lib/python27/dist-packages path, where it seems to me it should really be looking...
In any case, I was hoping someone might be able to give me some direction on what to try next.

Resources