Code Monkey home page Code Monkey logo

Comments (10)

DeviceNut avatar DeviceNut commented on May 22, 2024 1

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.

rodja avatar rodja commented on May 22, 2024

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.

falkoschindler avatar falkoschindler commented on May 22, 2024

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.

DeviceNut avatar DeviceNut commented on May 22, 2024

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.

falkoschindler avatar falkoschindler commented on May 22, 2024

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.

falkoschindler avatar falkoschindler commented on May 22, 2024

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.

DeviceNut avatar DeviceNut commented on May 22, 2024

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.

DeviceNut avatar DeviceNut commented on May 22, 2024

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.

falkoschindler avatar falkoschindler commented on May 22, 2024

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:

  1. You could add a print(filepath, flush=True) before config.py:41 to check which file is analyzed.
  2. 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.

falkoschindler avatar falkoschindler commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.