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

Could not find and pre-evaluate ui.run(). Starting interactive mode without auto-reload. #33

Closed
me21 opened this issue May 25, 2022 · 4 comments

Comments

@me21
Copy link
Contributor

me21 commented May 25, 2022

I've repeated the sample from your website in my project in PyCharm:

from nicegui import ui

ui.label('Hello NiceGUI!')
ui.button('BUTTON', on_click=lambda: ui.notify('button was pressed'))

ui.run()

However, when I debug it, I get the following output:

"C:\Users\azarubkin\Documents\Python Projects\evolve_web\venv\Scripts\python.exe" "C:\Program Files\JetBrains\PyCharm 2021.2.3\plugins\python\helpers\pydev\pydevd.py" --multiprocess --qt-support=auto --client 127.0.0.1 --port 63893 --file "C:/Users/azarubkin/Documents/Python Projects/evolve_web/nicegui_main.py"
Connected to pydev debugger (build 221.5591.52)
Could not find and pre-evaluate ui.run(). Starting interactive mode without auto-reload.
C:/Users/azarubkin/Documents/Python Projects/evolve_web/venv/lib/site-packages/justpy
Module directory: C:\Users\azarubkin\Documents\Python Projects\evolve_web\venv\lib\site-packages\justpy, Application directory: C:\Users\azarubkin\Documents\Python Projects\evolve_web
JustPy ready to go on http://0.0.0.0:8080

How can I fix this so that I get hot reloading?

@me21
Copy link
Contributor Author

me21 commented May 25, 2022

I've found that the cause is due to how configuration object is filled, by parsing the source of the file being run, and in case of debugging in PyCharm, this is pydevd.py, not nicegui_main.py.
If I run without debugging, no such message appears, but another warning pops up:

The --reload flag should not be used in production on Windows.

@falkoschindler
Copy link
Contributor

That's caused by the way NiceGUI pre-evaluates the ui.run command while evaluating from nicegui import ui. It has to know, whether it should start a uvicorn server with the reload flag (which will in turn evaluate the main script) or if the main script is evaluated first and the server is started by calling ui.run. Therefore it evaluates the call stack in config.py at around line 37 to find your main script. When using interactive interpreters or debuggers, they appear in the call stack and have to be filtered. We tried to do that for some IDEs, but surely missed some.

In your case, I assume we can simply add "pydevd.py" to the list of excluded_strings. Maybe you can try that out for me, since I have currently no PyCharm installed. If something is weird, it might help to print all f.filename within the for-loop to see the whole call stack. Thanks!

@me21
Copy link
Contributor Author

me21 commented Jun 7, 2022

I had to add 'pydevd.py' and '_pydev_execfile.py'. Thanks for the suggestion.

@falkoschindler
Copy link
Contributor

Great! I'm adding these filenames in version 0.7.28.

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