hanjinliu / magic-class

Generate multifunctional and macro recordable GUIs from Python classes
https://hanjinliu.github.io/magic-class/
BSD 3-Clause "New" or "Revised" License
40 stars 5 forks source link

Problem to run any example #3

Closed sebi06 closed 2 years ago

sebi06 commented 2 years ago

Hi,

I tried to run any of the example on my Python 3.8 on a Ubuntu 20.04 but get always errors like this:

/home/sebi06/miniconda3/envs/imageanalysis_czi/bin/python /datadisk1/tuxedo/Github/magic-class/examples/advanced/graph_viewer.py
Traceback (most recent call last):
  File "/datadisk1/tuxedo/Github/magic-class/examples/advanced/graph_viewer.py", line 1, in 
    from magicclass import magicclass, field, click, magicmenu, magiccontext
  File "/datadisk1/tuxedo/Github/magic-class/magicclass/__init__.py", line 3, in 
    from .core import (magicclass, magicmenu, magiccontext, WidgetType, Parameters, Bound, 
  File "/datadisk1/tuxedo/Github/magic-class/magicclass/core.py", line 11, in 
    from macrokit import Expr, register_type, Head
  File "/home/sebi06/miniconda3/envs/imageanalysis_czi/lib/python3.8/site-packages/macrokit/__init__.py", line 4, in 
    from .expression import Expr, Head, symbol
  File "/home/sebi06/miniconda3/envs/imageanalysis_czi/lib/python3.8/site-packages/macrokit/expression.py", line 8, in 
    from ._validator import validator
  File "/home/sebi06/miniconda3/envs/imageanalysis_czi/lib/python3.8/site-packages/macrokit/_validator.py", line 37, in 
    validator = Validator[Head, list[Any]]()
TypeError: 'type' object is not subscriptable

Process finished with exit code 1

Any hint what I am doing wrong here?

hanjinliu commented 2 years ago

Hi @sebi06,

I forgot testing macrokit in Python < 3.9 and that type annotation is not supported in Python 3.8. I'll fix it soon but if you want to try them now you could make another environment with Python 3.9 installed. I'll let you know after I fix it. Thank you!

sebi06 commented 2 years ago

Now the error message is gone, but nothing shows up. For a fraction of a second there seems to be a window poping up, but there is no graph_viewer window etc.

/home/sebi06/miniconda3/envs/napari-env/bin/python /datadisk1/tuxedo/Github/magic-class/examples/advanced/graph_viewer.py

Process finished with exit code 0
            
hanjinliu commented 2 years ago

I've just fixed bugs so I think you can also try with python 3.8.

Running GUI with python command always face that problem because just after opening the main widget python itself stops. You can use -i option, like .../python -i .../example_file.py to prevent python from exiting immediately. But it may be safer to open Jupyter Notebook or Jupyter QtConsole and copy-and-pasting the code in it.

hanjinliu commented 2 years ago

Hi @sebi06, I found a way to prevent the main window from quitting while keep API consistent. In v0.5.14 you can just call .../python .../example_file.py to try any scripts. Sorry for inconvenience but I hope this update will help you.

captainhunt commented 11 months ago

I am facing exactly the same issue using python 3.11.3 magic-class 0.7.6: calling examples with python example.py just quits the main window immediately. running python -i example.py works however, the interpreter runs even if I quit the main window. Is this expected? How am I supposed to run the examples?

hanjinliu commented 11 months ago

Hi @captainhunt , thank you for letting me know, probably some changes since this issue being closed caused the problem... I'm thinking of letting users to specify whether it is needed to run the application so that the window keeps showing, just like magicgui and napari (in current implementation magic-class automatically determine whether to run or not). I'll reopen this as another issue and hopefully fix it soon.

running python -i example.py works however, the interpreter runs even if I quit the main window.

This behavior is expected eitherway, as -i indicates that the Python interpreter should be launched, which is independent of the GUI.