I decided to look into Pyglet to experiment with graphics and hit the ground face first with some errors. Right off the bat, I had issue simply trying to create a window. I would get multiple errors due to the fact that I was using the 64-bit version of Python. I've switched to 32-bit, and whittled down the errors to this one:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
window = pyglet.window.Window()
File "C:\Python27\lib\site-packages\pyglet\window\win32\__init__.py", line 423, in __init__
super(Win32Window, self).__init__(*args, **kwargs)
File "C:\Python27\lib\site-packages\pyglet\window\__init__.py", line 686, in __init__
self._create()
File "C:\Python27\lib\site-packages\pyglet\window\win32\__init__.py", line 518, in _create
self.context._set_window(self)
File "C:\Python27\lib\site-packages\pyglet\window\win32\__init__.py", line 364, in _set_window
raise gl.ContextException('Unable to share contexts')
ContextException: Unable to share contexts
The error was caused by this line of code, which is the first line in the Pyglet tutorial on their website (omitting the import):
window = pyglet.window.Window()
It's worth noting that I have two monitors. According to the Pyglet documentation, it shouldn't be a problem as it chooses default values, but I don't want to rule it out.
EDIT: I'm working on Windows 7 64-bit.
Related
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.
I was running a tower defence game in the arcade module but after I press start, the game freezes up and returns with
Traceback (most recent call last):
File "D:\lib\site-packages\arcade\text.py", line 278, in draw_text
label = draw_text_cache[key]
KeyError: "05064200240left('Calibri', 'Arial')FalseFalse"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ThisPC\Downloads\The Great Skeleton War\lab_12.py", line 2890, in <module>
arcade.run()
File "D:\lib\site-packages\arcade\window_commands.py", line 236, in run
pyglet.app.run()
File "D:\lib\site-packages\pyglet\app\__init__.py", line 107, in run
event_loop.run()
File "D:\lib\site-packages\pyglet\app\base.py", line 167, in run
timeout = self.idle()
File "D:\lib\site-packages\pyglet\app\base.py", line 243, in idle
window.dispatch_event('on_draw')
File "D:\lib\site-packages\pyglet\window\__init__.py", line 1333, in dispatch_event
if EventDispatcher.dispatch_event(self, *args) != False:
File "D:\lib\site-packages\pyglet\event.py", line 422, in dispatch_event
self._raise_dispatch_exception(event_type, args, getattr(self, event_type), exception)
File "D:\lib\site-packages\pyglet\event.py", line 476, in _raise_dispatch_exception
raise exception
File "D:\lib\site-packages\pyglet\event.py", line 415, in dispatch_event
if getattr(self, event_type)(*args):
File "C:\Users\ThisPC\Downloads\The Great Skeleton War\lab_12.py", line 1136, in on_draw
arcade.render_text(globalvars.level_text, SCREEN_WIDTH - 104, SCREEN_HEIGHT - 50)
File "D:\lib\site-packages\arcade\text.py", line 88, in render_text
draw_text(text.text,
File "D:\lib\site-packages\arcade\text.py", line 281, in draw_text
image = get_text_image(text=text,
File "D:\lib\site-packages\arcade\text.py", line 218, in get_text_image
draw.multiline_text((image_start_x, image_start_y), text, text_color, align=align, font=font)
File "D:\lib\site-packages\PIL\ImageDraw.py", line 446, in multiline_text
self.text(
File "D:\lib\site-packages\PIL\ImageDraw.py", line 365, in text
ink = getink(fill)
File "D:\lib\site-packages\PIL\ImageDraw.py", line 313, in getink
ink, fill = self._getink(fill)
File "D:\lib\site-packages\PIL\ImageDraw.py", line 112, in _getink
ink = self.draw.draw_ink(ink)
TypeError: color must be int or tuple
And I'm not really sure why. It says my python packages are wrong so I uninstalled and reinstalled python multiple times too.
Can anyone help me?
Thanks in advance btw.
Without any code, this is hard. But here's my guess.
Perhaps it was made for Python 2 instead of Python 3, or the modules have been updated. Normally Python programs are run inside a virtual environments and have a requirements.txt file for the module versions. You can activate a virtual environment, install the packages and run it.
The issue arises from the wrong data type, the variable color should be of the type int or tuple. On line 278 of the file "D:\lib\site-packages\arcade\text.py" in draw_text, what is the type(key)?
Without code, it's hard to answer.
I think that when you decided the color that you wanted to use, probably in a text that you want to write on the screen, you chose the wrong format. You probably passed an array instead of a tuple that has this form: (int, int, int). (for (r, g, b)) if you did use an array you can still use it but you'll have to add the tuple(your_array) command when you're passing it at the place you want to pass it to.
I need to display notifications in MacOS. Simply running the script with python can display notification. But whenever I pack the script using Pyinstaller, I get the following error. Seems like Pyinstaller is having some problem with working on Mac notifications. I also tried using pync (Python binding for terminal notifier). In all cases, simply running the app python notify.py works, but freezing the script using Pyinstaller doesn't seem to work.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/Foundation/__init__.py", line 10, in <module>
from CoreFoundation import *
File "/Library/Python/2.7/site-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/Users/jacob/mac-notify/build/notify/out00-PYZ.pyz/CoreFoundation", line 19, in <module>
File "/Users/jacob/mac-notify/build/notify/out00-PYZ.pyz/objc._bridgesupport", line 121, in initFrameworkWrapper
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 939, in resource_exists
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 1392, in has_resource
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 1447, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
logout
I am using the following Python script to display notification
import Foundation
import objc
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
notification = NSUserNotification.alloc().init()
notification.setTitle_("TestTitle")
notification.setInformativeText_("This is sample text")
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.deliverNotification_(notification)
I had similar problems and this is how I made it work. You need not use Foundation as its making the problem with Pyinstaller (Not sure why this is causing an issue) and is not used elsewhere in your code.
import objc
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
notification = NSUserNotification.alloc().init()
notification.setTitle_("TestTitle")
notification.setInformativeText_("This is sample text")
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.deliverNotification_(notification)
At this point, it may throw some error or the notification just don't show up. Just add CFBundleIdentifier key into the info.plist file generated by pyinstaller.
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.
Edit : Array should be CvMat or IplImage is not an error message specific to this issue, that's the only most relevant error message i got.
I'm trying to make an *.exe out of an application using opencv.
I'm using Python 2.6 and openCV 2.1.
I can run part of the *.exe, i'm having a menu from where i can choose to process some pictures from 2 differents sources my webcam & a static image. The static image part works but when i'm chosing the webcam here is the output:
OpenCV Error: Bad argument (Array should be CvMat or IplImage) in unknown function, file ..\..\..\..\ocv\opencv\src\cxcore\cxarray.cpp,
line 1233
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 295, in 'calling callback function'
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.window.win32", line 849, in _wnd_proc
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.window.win32", line 918, in _event_key
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.window", line 1219, in dispatch_event
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.event", line 340, in dispatch_event
File "", line 502, in on_key_press
File "", line 461, in dostart
File "", line 482, in getpoints
File "D:\Prog\Python\AugmentedR\src\pyar.py", line 40, in get_points
pilimage = Image.fromstring("RGB", cv.GetSize(image), image.tostring())
cv.error: Array should be CvMat or IplImage
Traceback (most recent call last):
File "", line 616, in
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.app", line 264, in run
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.app.win32", line 63, in run
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.app.win32", line 84, in _timer_func
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.app", line 193, in idle
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.window", line 1219, in dispatch_event
File "game_ar\build\pyi.win32\game_ar\outPYZ1.pyz/pyglet.event", line 340, in dispatch_event
File "", line 546, in on_draw
AttributeError: Game instance has no attribute 'bg'
My pyar.py file.
Building the *.exe with py2exe gave me this output :
The following modules appear to be missing
['ICCProfile', '_imaging_gif', '_scproxy']
I don't get it, this is working with my sources. I tried to pack my application with py2exe & pyinstaller, but the output is the same.
I guess the *.exe is missing something but i don't know what neither how to debug it.
It was not related to the packagers.
The problem was that I wasn't closing the webcam capture, several processes of my app were actually running in the background.
The doc is talking about ReleaseCapture but this function is apparently not in the python bindings, calling :
del(self.cam)
did the job just well, self.cam being my CvCapture object.