pthom / imgui_bundle

Dear ImGui Bundle: an extensive set of Ready-to-use widgets and libraries, based on ImGui. Start your first app in 5 lines of code, or less. Whether you prefer Python or C++, this pack has your back!
https://pthom.github.io/imgui_bundle/
MIT License
592 stars 63 forks source link

python 3.12 breakage on demo_imgui_bundle.py #144

Closed jhgorse closed 7 months ago

jhgorse commented 7 months ago

Excerpt: ModuleNotFoundError: No module named 'imp' when trying to run unloaded modules of python code.

What the python hive mind has decided, FYI: https://discuss.python.org/t/how-do-i-migrate-from-imp/27885/28

Log for reference:

(.venv) jhgs-MacBook-Air:pyimgui jhg$  cd /opt/work/pyimgui ; /usr/bin/env /opt/work/pyimgui/.venv/bin/python /Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 49427 -- /opt/work/pyimgui/main.py 
For information, demos sources are available in /opt/work/pyimgui/.venv/lib/python3.12/site-packages/imgui_bundle/demos_python
WARNING: Output of vertex shader 'Frag_Color' not read by fragment shader

0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Traceback (most recent call last):
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
    main()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
    globals = debugger.run(setup['file'], None, None, is_module)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2445, in run
    m = save_main_module(file, 'pydevd')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py", line 32, in save_main_module
    from imp import new_module
ModuleNotFoundError: No module named 'imp'
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Traceback (most recent call last):
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
    main()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
    globals = debugger.run(setup['file'], None, None, is_module)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2445, in run
    m = save_main_module(file, 'pydevd')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py", line 32, in save_main_module
    from imp import new_module
ModuleNotFoundError: No module named 'imp'
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Traceback (most recent call last):
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
    main()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
    globals = debugger.run(setup['file'], None, None, is_module)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2445, in run
    m = save_main_module(file, 'pydevd')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py", line 32, in save_main_module
    from imp import new_module
ModuleNotFoundError: No module named 'imp'
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Traceback (most recent call last):
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
    main()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
    globals = debugger.run(setup['file'], None, None, is_module)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2445, in run
    m = save_main_module(file, 'pydevd')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py", line 32, in save_main_module
    from imp import new_module
ModuleNotFoundError: No module named 'imp'
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Traceback (most recent call last):
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
    main()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
    globals = debugger.run(setup['file'], None, None, is_module)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2445, in run
    m = save_main_module(file, 'pydevd')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py", line 32, in save_main_module
    from imp import new_module
ModuleNotFoundError: No module named 'imp'
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Traceback (most recent call last):
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
    main()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
    globals = debugger.run(setup['file'], None, None, is_module)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2445, in run
    m = save_main_module(file, 'pydevd')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py", line 32, in save_main_module
    from imp import new_module
ModuleNotFoundError: No module named 'imp'
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Traceback (most recent call last):
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
    main()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
    globals = debugger.run(setup['file'], None, None, is_module)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2445, in run
    m = save_main_module(file, 'pydevd')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py", line 32, in save_main_module
    from imp import new_module
ModuleNotFoundError: No module named 'imp'
^CTraceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.12/3.12.0/Frameworks/Python.framework/Versions/3.12/lib/python3.12/runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.0/Frameworks/Python.framework/Versions/3.12/lib/python3.12/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/opt/work/pyimgui/main.py", line 130, in <module>
    main()
  File "/opt/work/pyimgui/main.py", line 126, in main
    immapp.run(runner_params=runner_params, add_ons_params=addons)
  File "/opt/work/pyimgui/main.py", line 106, in show_gui
    @static(nb_frames=0)

  File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_trace_dispatch_regular.py", line 326, in __call__
    def __call__(self, frame, event, arg):
pthom commented 7 months ago

Hi,

Thanks for contacting me. I cannot reproduce your issue.

Based on your command line, I can diagnose several things:

(.venv) jhgs-MacBook-Air:pyimgui jhg$  cd /opt/work/pyimgui ; /usr/bin/env /opt/work/pyimgui/.venv/bin/python /Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 49427 -- /opt/work/pyimgui/main.py 

I happens inside a file/opt/work/pyimgui/main.py, I do not know what is its content.

However, please note that imgui_bundle bindings are separate from pyimgui. They can coexist in the same virtual environment, however the following python code would fail!

import imgui # import imgui from pyimgui
from imgui_bundle import imgui # import imgui from imgui_bundle

As far as your error is concerned, here are the relevant lines:

File "/Users/jhg/.cursor/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.py", line 32, in save_main_module
    from imp import new_module
ModuleNotFoundError: No module named 'imp'

It seems to happen inside debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_utils.pywhich is probably part of pydevd, and possibly installed by vscode (no idea about why it is inside /Users/jhg/.cursor/extension)

jhgorse commented 7 months ago

It was an ambiguous choice of directory name, pyimgui, though I have evaluated 3 python bindings to dear imgui. I liked your bundle for the local debug-able c++.

I am using cursor.sh, a vscode clone. With the msft python extension. main.py is the imgui_bundle_demo.py code.

For some reason, the demo app on macOS arm64 python3.12 fails to launch the external code references. The above pydev errors are what I see after the new window fails to materialize.

When I resolve those errors by regressing back to python 3.11, the demo code works and launches as we would expect in the vscode debug environment.

Running without vscode on python3.12 works. The references code executes and windows appear.

It seems this is not your problem.