Comments (10)
Here's the problem: Windows uses forward slashes, so your list of filenames to exclude needs to include names using them as well. Made that change and it works.
from nicegui.
Maybe you've set another python version as default interpreter within vscode? Could you try running the following script
from nicegui import ui
import nicegui
import sys
print(sys.version)
print(nicegui.__file__)
ui.run()
and provide to output when running from command line vs vscode?
from nicegui.
Please note, that from version 0.4.0 NiceGUI requires a ui.run()
command in the main script. It should be located at "top level" and not nested in a class, function, condition or loop (thus not indented). So if VSCode runs with a different Python installation with a newer NiceGUI version, it would explain the different behavior.
from nicegui.
It fails on the import statement itself (either from nicegui import ui
, or just import nicegui
), only when running with the debugger. Running without the debugger, or from the command line, works.
Here's the output when running to the above snippet:
3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)]
C:\Python\lib\site-packages\nicegui\__init__.py
So it's something to do with VSCode's debugger, but I've never seen this happen with anything else.
from nicegui.
Although it might be possible that the VSCode debugger conflicts with NiceGUI's internal reload detection mechanism, I'm struggling to reproduce the problem. When starting something like
from nicegui import ui
def click():
print('click', flush=True)
ui.label('Hello world!')
ui.button('Click me', on_click=click)
ui.run()
with "Run">"Start Debugging">"Python File: Debug the currently active Python file", the Uvicorn server starts nicely, the browser opens a new tab on localhost:80 and I can set breakpoints (e.g. in the event handler of a simple button).
Maybe VSCode runs the debugger differently on Windows than on Mac?
from nicegui.
It fails on the import statement itself
An error in the import statement might have to do with the ui.run()
command: NiceGUI needs to decide whether to immediately start a Uvicorn server with auto-reload activated or to continue evaluating the main script and to start the server later during ui.run()
. It does so by inspecting the main script if ui.run()
will be called with reload=True
. If this approach causes issues in certain development environments, we're eager to resolve the issue.
from nicegui.
Sounds like that is causing the issue on my setup. Curious it works fine on yours. Perhaps it's a side effect of some extensions I've got loaded (a bunch of stuff for python/javascript/npm/react/etc.)?
And like I said, it works fine without "debugging". I'm not a VSCode guru so I don't know what else to do here.
You might want to see if anyone else can repro this, or it's just me.
from nicegui.
Right, so it's your code at config.py:41 that is causing this. Why it's not finding the ui.run() call in the main source I don't know.
Also, it's opening 0.0.0.0 not localhost, which doesn't work. If I redirect to localhost it connects.
from nicegui.
I suspect that the debugger calls your main script with some wrapper and NiceGUI is looking for ui.run() in the wrong file. There are two things that would be of great help:
- You could add a
print(filepath, flush=True)
before config.py:41 to check which file is analyzed. - If it's the wrong one, you could add
print(f.filename)
in config.py:19 to show all the files in the call stack.
Maybe we need to add a new exception in endings
... or find a better way to search for the main file.
And thanks for the hint about 0.0.0.0 vs. localhost. Although the server is starting with IP 0.0.0.0, the browser should open localhost.
from nicegui.
Awesome! We totally forgot to use platform-independent file paths. I fixed it in Release 0.4.7. It also addresses the issue with Host 0.0.0.0.
Thanks @DeviceNut for your contribution!
from nicegui.
Related Issues (20)
- Plotly chart changes position after updating the chart. HOT 10
- ⚠️ `ui.upload` File upload stops at 99.9% HOT 1
- 3D visualization not reliable HOT 15
- From 188c81b on some pages load extremely slowly HOT 9
- I use pyinstaller to generate .exe file find question, how to solve it?
- Setting ui.number min/max property is failing after version nicegui-1.4.19 HOT 1
- When executing the run_method , a KeyError error occurs. HOT 6
- Native mode [Windows] : Stay on top option
- Firefox cannot establish the websocket connection but other browsers and firefox private browsing can. HOT 8
- app.storage.user in unit tests throws error. HOT 1
- confilict with multiprocessing when running in native mode? HOT 1
- Infinite scroll example errors HOT 5
- Nginx subpath example doesn't redirect correctly when navigating to subpage with trailing slash
- ui.plotly chart randomly collapses / shrinks HOT 2
- Leaflet always uses the full width
- Troubles while periodically updating the 3D scene HOT 6
- Native mode and resizability of the window HOT 4
- Text in input and select components is not aligned to each other HOT 5
- ui.input validation will remain space after it's value was corrected HOT 3
- Select fails to change value on first try. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nicegui.