i am trying to create a windows webviewer in pyhton, i tried python webview but i always get a module error

118 views Asked by At

why is it that my python webview code does not work

import webview
webview.create_window("Ridola Web View", "www.google.com")
webview.start()

Giving me this error

Traceback (most recent call last):
  File "C:\Users\user\Desktop\LiveViewer\webview.py", line 81, in <module>
    import webview
  File "C:\Users\user\Desktop\LiveViewer\webview.py", line 82, in <module>
    webview.create_window("Ridola Web View", "www.google.com")
AttributeError: partially initialized module 'webview' has no attribute 'create_window' (most likely due to a circular import)
2

There are 2 answers

0
gtj520 On

When importing a module or a library, Python looks for it from sys.path. If there is a module or a script, which share the same filename as your library, listed before the library in sys.path, Python would import the module or the script. In this case, there would be never-ending importing becaue the module or the script is importing itself repeatedly. To avoid such situation, you should avoid naming scripts and modules identical to libraries you wish to import.

If your script or any imported script has the identical filename to webview, such as webview.py, please rename it to avoid any conflict.

0
Rajanand On

This error occurred due to the name of your file.

I guess the name of your Python file is "webview.py" and webview.py is already a dependency when you call,

import webview

so this led to circular import where the Python file imported itself in an infinite loop.

renaming your file will work well without errors.