Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using pyglet breaks on newer Python versions #361

Open
RussellDash332 opened this issue Oct 31, 2024 · 3 comments
Open

Using pyglet breaks on newer Python versions #361

RussellDash332 opened this issue Oct 31, 2024 · 3 comments

Comments

@RussellDash332
Copy link

Disclaimer

This is mainly suited for Windows. I am not sure if the same issue happens on Mac or other OSes.

Python 3.12

Since Python 3.12, there is a bug when using the latest version of cocos, specifically this line. It could be due to the new importing behaviors that music is not defined even after importing cocos.audio.

Current solution is to set a dummy attribute mock_level on Pyglet like this.

import sys
setattr(sys.modules['pyglet'], 'mock_level', None) # can replace None with any value

How to reproduce the issue:

# Use Python 3.12
import cocos
cocos.director.director.init(width=128, height=128, autoscale=False)

Python 3.13

The metaclass inheritance breaks on this version of Python, mainly caused by this line.

Based on pyglet/pyglet#288, the solution is to currently degrade pyglet to the version before the PR in question was made, which is v1.5.8.

How to reproduce the issue:

# Use Python 3.13
import cocos
@ccanepa
Copy link
Contributor

ccanepa commented Oct 31, 2024

Thanks for the report and posible workarounds

Audio, import: yes, a change in python 3.12 imports resolution broke cocos. I missed the time to track the relevant import chain for a proper fix.

You inject the dummy at the top of a user script, coco's __init__ or ....?

Python 3.13: pyglet 1.5.8 is ancient, not sure if something else would break for (last cocos, pyglet 1.5.8, py3.13)

If a pure pyglet script, like noisy.py or another of pyglet demo examples shows this issue it would be better to report to pyglet, and wait for their fix.

If you want to look at that it would be great, if not I will try that route in a few days, I'm not on a 3.13-able machine ATM

One more time, thanks

@RussellDash332
Copy link
Author

RussellDash332 commented Oct 31, 2024

You inject the dummy at the top of a user script, coco's init or ....?

At my own script, I wanted to remain cocos untouched.

If a pure pyglet script, like noisy.py or another of pyglet demo examples shows this issue it would be better to report to pyglet, and wait for their fix.

I was thinking that it would be weird to report the current issue to pyglet since they are already at v2.0.18. Since we restrict cocos's dependency on pyglet to be below v2.0 we can customize this further.

Here's the full traceback when I import cocos on Python 3.13 (with pyglet==1.5.29 since that's the latest compatible version to cocos)

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\cocos\fps.py", line 57, in <module>
    from pyglet.clock import ClockDisplay
ImportError: cannot import name 'ClockDisplay' from 'pyglet.clock' (C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyglet\clock.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import cocos
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\cocos\__init__.py", line 123, in <module>
    from cocos import cocosnode
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\cocos\cocosnode.py", line 51, in <module>
    from cocos.director import director
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\cocos\director.py", line 132, in <module>
    import cocos.fps
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\cocos\fps.py", line 59, in <module>
    from pyglet.window import FPSDisplay as ClockDisplay
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyglet\window\__init__.py", line 1912, in <module>
    from pyglet.window.win32 import Win32Window as Window
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyglet\window\win32\__init__.py", line 50, in <module>
    from pyglet.canvas.win32 import Win32Canvas
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyglet\canvas\__init__.py", line 110, in <module>
    from pyglet.canvas.win32 import Win32Display as Display
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyglet\canvas\win32.py", line 3, in <module>
    from pyglet.libs.win32 import _user32
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyglet\libs\win32\__init__.py", line 41, in <module>
    from . import com
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyglet\libs\win32\com.py", line 240, in <module>
    class COMPointer(ctypes.c_void_p, metaclass=COMPointerMeta):
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyglet\libs\win32\com.py", line 214, in __new__
    _pointer_type_cache[cls] = type(COMPointer)("POINTER({})".format(cls.__name__),
NameError: name 'COMPointer' is not defined. Did you mean: 'COMPointerMeta'?

@ccanepa
Copy link
Contributor

ccanepa commented Nov 27, 2024

reproduced with pyglet 1.5-maitenance, issue opened there
pyglet/pyglet#1238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants