Can't understand the error - python

Given below is the error which I am getting while running the code (which is in my previous post wx Import Error) in Python 2.6. Can anyone tell about this error? I am unable to understand it.
Traceback (most recent call last):
File "C:\Python26\music_player_v1\player_skeleton.py", line 153, in <module>
frame = MediaFrame()
File "C:\Python26\music_player_v1\player_skeleton.py", line 148, in __init__
panel = MediaPanel(self)
File "C:\Python26\music_player_v1\player_skeleton.py", line 25, in __init__
self.layoutControls()
File "C:\Python26\music_player_v1\player_skeleton.py", line 46, in layoutControls
audioTBSizer = self.buildAudioToolBar()
File "C:\Python26\music_player_v1\player_skeleton.py", line 65, in buildAudioToolBar
self.rewind = SBitmapButton(self, -1, upbmp, (48, 48))
File "C:\Python26\Lib\wx-2.8-msw-unicode\wx\lib\agw\shapedbutton.py", line 995, in __init__
self.SetBitmapLabel(bitmap)
File "C:\Python26\Lib\wx-2.8-msw-unicode\wx\lib\agw\shapedbutton.py", line 1068, in SetBitmapLabel
image = wx.ImageFromBitmap(bitmap)
File "C:\Python26\Lib\wx-2.8-msw-unicode\wx\_core.py", line 3473, in ImageFromBitmap
val = _core_.new_ImageFromBitmap(*args, **kwargs)
PyAssertionError: C++ assertion "bmp.Ok()" failed at ..\..\src\msw\dib.cpp(148) in wxDIB::Create(): wxDIB::Create(): invalid bitmap

Not sure if this is entirely related to your problem, but the SWIG-generated wrappers won't hold onto any Python objects passed to any set*() methods or the like in wx. You will need to hold onto such objects yourself or you will experience strange errors.

It looks like you have an invalid bitmap. In reading the tracebacks, it's usually the bottom traceback that's the most useful, and this one is saying that you have an "invalid bitmap".

Your application cant find an image file, put all images in one file and in your code give the exact path where to find the images.That wil solve that error.

Related

How to debug the error message from a yapf formatting task?

I recently inherited a code base and am in the process of using yapf (and indirectly lib2to3) to format the code base. When I run the formatter I get the following output:
Traceback (most recent call last):
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/yapf_api.py", line 183, in FormatCode
tree = pytree_utils.ParseCodeToTree(unformatted_source)
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/pytree_utils.py", line 125, in ParseCodeToTree
tree = parser_driver.parse_string(code, debug=False)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/driver.py", line 103, in parse_string
return self.parse_tokens(tokens, debug)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/driver.py", line 71, in parse_tokens
if p.addtoken(type, value, (prefix, start)):
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/parse.py", line 119, in addtoken
ilabel = self.classify(type, value, context)
File "/opt/homebrew/Cellar/python#3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib2to3/pgen2/parse.py", line 175, in classify
raise ParseError("bad token", type, value, context)
lib2to3.pgen2.parse.ParseError: bad token: type=58, value='ִ', context=('', (325, 19))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/module/venv/lib/python3.9/site-packages/yapf/__init__.py", line 225, in _FormatFile
reformatted_code, encoding, has_change = yapf_api.FormatFile(
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/yapf_api.py", line 96, in FormatFile
reformatted_source, changed = FormatCode(
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/yapf_api.py", line 186, in FormatCode
raise errors.YapfError(errors.FormatErrorMsg(e))
File "/module/venv/lib/python3.9/site-packages/yapf/yapflib/errors.py", line 37, in FormatErrorMsg
return '{}:{}:{}: {}'.format(e.args[1][0], e.args[1][1], e.args[1][2], e.msg)
IndexError: tuple index out of range
It seems that the error arises from a unicode character from the lib2to3.pgen2.parse.ParseError: bad token: type=58, value='ִ', context=('', (325, 19)) error, though I am unsure how to 1) find the source of the error and 2) how to fix it if I do find it.
As of now, I don't believe that unicode character is in the codebase; though, the codebase is fairly large so it is entirely possible that I am just missing it somewhere.
Does anyone have any experience parsing these types of errors or can point me in the right direction?
I found a few github issues describing this type of error, but they remain Open with no direction on finding the source.

Open visio using python

I've a weird problem. I have coded a little python script to test if my idea would work (no worries, it's just for fun). I am trying to simply open visio, place a couple of objects and close it.
#Get visio application
import win32com.client as win32
visio = win32.gencache.EnsureDispatch('Visio.Application')
visio.Visible = True
And it worked, so I've left it as it is for this week and when I tested it again it gave me an error which didn't occur last time, and closed the application.
Traceback (most recent call last):
File "c:\Users\lars\OneDrive - HAN\School LJ 3\Stage\Stageopdrachten\Opdracht interactive netwerktekening\Programma\main.py", line 3, in <module>
visio = win32.gencache.EnsureDispatch('Visio.Application')
File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 524, in EnsureDispatch
disp = win32com.client.Dispatch(prog_id)
File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\__init__.py", line 96, in Dispatch
return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\__init__.py", line 37, in __WrapDispatch
klass = gencache.GetClassForCLSID(resultCLSID)
File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 180, in GetClassForCLSID
mod = GetModuleForCLSID(clsid)
File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 223, in GetModuleForCLSID
mod = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 263, in GetModuleForTypelib
AddModuleToCache(typelibCLSID, lcid, major, minor)
File "C:\Users\lars\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\win32com\client\gencache.py", line 559, in AddModuleToCache
SetTypelibForAllClsids(mod.CLSIDToClassMap)
AttributeError: module 'win32com.gen_py.00021A98-0000-0000-C000-000000000046x0x4x16' has no attribute 'CLSIDToClassMap'
Does anybody know what happened, or what I'm doing wrong? I've tried to reverse an update that happened in the meantime. I've been looking if the win32com has been updated. Yet nothing did solve it.
I appreciate your assistance.
The awnser to this question has been posted here:
Why am I suddenly getting a no attribute 'CLSIDToPackageMap' error with win32com.client?
In short the problem can be solved by deleting the gen_py folder found in the temp folder. You can find the temp folder by searching for %temp% or go to c:\users<username>\appdata\local\temp (make sure to show hidden files).
Hope I was able to help.

wxPython: GenericDirCtrl

i'm trying to display a directory tree within a panel in wxpython. I'm using this line of code for the purpose:
self.dir = wx.GenericDirCtrl(rightpanel, -1, dir='C:',
style=wx.DIRCTRL_DIR_ONLY,
size=wx.Size(60, 60))
but i get this huge error message:
Traceback (most recent call last):
File "C:\Python27\3pane.py", line 85, in <module>
app = MyApp(0)
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 8628, in __init__
self._BootstrapApp()
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 8196, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Python27\3pane.py", line 79, in OnInit
frame = MyFrame(None, -1, 'TAA')
File "C:\Python27\3pane.py", line 55, in __init__
size=wx.Size(60, 60))
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_controls.py", line 5663, in __init__
_controls_.GenericDirCtrl_swiginit(self,_controls_.new_GenericDirCtrl(*args, **kwargs))
PyAssertionError: C++ assertion "strcmp(setlocale(LC_ALL, NULL), "C") == 0" failed at ..\..\src\common\intl.cpp(1449) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a mismatch between C/C++ and Windows locale.
Things are going to break, please only change locale by creating wxLocale objects to avoid this!
i really need help with this.
Thanks.

Cannot determine type of file

Hi i have just started learning image processing using python.
When i tried to open an image that i downloaded from the net, I keep getting this error and I have no idea about how to resolve it. Can anyone please help me with this?
>>> dna=mahotas.imread('dna.jpeg')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 773, in imread
img = read(filename)
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 444, in read
bitmap = _read_bitmap(filename, flags)
File "C:\Python27\lib\site-packages\mahotas\io\freeimage.py", line 490, in _read_bitmap
'mahotas.freeimage: cannot determine type of file %s' % filename)
ValueError: mahotas.freeimage: cannot determine type of file dna.jpeg
Hello this looks like a pretty old thread but I found it recently because I had the same problem.
I think that the error message is misleading because it implies that the type of file is incorrect.
I fixed the problem by including the full path to the image file. For example, it could look something like:
dna = mahotas.imread('C:\Documents\dna.jpeg')

Error with Gamma Correction in Psychopy

I'm trying to gamma correct my computer monitor using an OceanOptics Spectrometer to gather the data and Pyschopy's gamma correction module to linearize the curve.
The program appears to work around 4/5 times but will occasionally give me an error when I attempt to setGammaRamp. I was just what the error might be. Is it possible that it is a problem with 32-64 bit conversion using ctypes? Here's the error that I get:
Traceback (most recent call last):
File "C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\Lib\site-packages\aibs\chrisgammatest.py", line 139, in <module>
Calib=GammaTest()
File "C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\Lib\site-packages\aibs\chrisgammatest.py", line 22, in __init__
self.monitorcal()
File "C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\Lib\site-packages\aibs\chrisgammatest.py", line 81, in monitorcal
sample=self.gammaTest()
File "C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\Lib\site-packages\aibs\chrisgammatest.py", line 42, in gammaTest
window=visual.Window(units='norm',monitor=monitortype, fullscr = True, screen = screennumber, waitBlanking=True)
File "C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\psychopy\visual.py", line 334, in __init__
self.setGamma(self.gamma)#using either pygame or bits++
File "C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\psychopy\visual.py", line 935, in setGamma
self.winHandle.setGamma(self.winHandle, self.gamma)
File "C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\psychopy\gamma.py", line 34, in setGamma
setGammaRamp(pygletWindow, newLUT)
File "C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\psychopy\gamma.py", line 51, in setGammaRamp
success = windll.gdi32.SetDeviceGammaRamp(pygletWindow._dc, newRamp.ctypes)
ctypes.ArgumentError: argument 1: <type 'exceptions.OverflowError'>: long int too long to convert
There seems to be a 32/64 sign extension problem on GetDC() in ctypes / Pyglet / Psychopy.
See:
https://github.com/psychopy/psychopy/issues/504
It also appears that Windows doesn't allow all gamma settings, see:
http://jonls.dk/2010/09/windows-gamma-adjustments/

Categories