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

No module named 'utils' on simple_clock.html #641

Closed
3 tasks done
june9713 opened this issue Jul 29, 2022 · 3 comments
Closed
3 tasks done

No module named 'utils' on simple_clock.html #641

june9713 opened this issue Jul 29, 2022 · 3 comments

Comments

@june9713
Copy link

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a duplication
  • I already searched in Google and didn't find any good information or help

What is the issue/comment/problem?

I fully download this repo and run simple_clock.html file in examples folder by Chrome.
but it returns red errors, main massage is
No module named 'utils'
Anybody helpes me?

PyScript: Access to local files (using "Paths:" in ) is not available when directly opening a HTML file; you must use a webserver to serve the additional files. See this reference on starting a simple webserver with Python.

start time:
JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/site-packages/_pyodide/_base.py", line 429, in eval_code .run(globals, locals) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 300, in run coroutine = eval(self.code, globals, locals) File "", line 3, in ModuleNotFoundError: No module named 'utils' )
JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception File "/lib/python3.10/asyncio/tasks.py", line 232, in __step result = coro.send(None) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 500, in eval_code_async await CodeRunner( File "/lib/python3.10/site-packages/_pyodide/_base.py", line 351, in run_async coroutine = eval(self.code, globals, locals) File "", line 1, in ModuleNotFoundError: No module named 'utils' )

@june9713 june9713 added the needs-triage Issue needs triage label Jul 29, 2022
@JeffersGlass
Copy link
Member

The issue is that the Pyscript code (via py-env) is looking for a file called 'utils.py' and can't find one, though you've probably guessed that. Here's why:

By their very nature, browsers do not want websites to access things on your hard disk. You wouldn't want Twitter to be able to see your spreadsheets, right? If you're opening the example by, say, using File > Open in Chrome, or clicking on simple_clock.html in your file system, you are giving Chrome explicit permission to access that file, and only that file. Any other files on your hard drive, even if they're "right next to" the one you opened, are off limits.

The way around this is to grant explicit permission to your browser to access other files on your HD, like 'utils.py' that you need in this case. The way to that is to use a simple server program to make them available 'on the network' (even if just locally to your computer). The link in that above error message has a simple method - many IDE's, like VS Code or PyCharm, also have the ability to serve your files so the browser can access them.

@june9713
Copy link
Author

june9713 commented Aug 6, 2022

The issue is that the Pyscript code (via py-env) is looking for a file called 'utils.py' and can't find one, though you've probably guessed that. Here's why:

By their very nature, browsers do not want websites to access things on your hard disk. You wouldn't want Twitter to be able to see your spreadsheets, right? If you're opening the example by, say, using File > Open in Chrome, or clicking on simple_clock.html in your file system, you are giving Chrome explicit permission to access that file, and only that file. Any other files on your hard drive, even if they're "right next to" the one you opened, are off limits.

The way around this is to grant explicit permission to your browser to access other files on your HD, like 'utils.py' that you need in this case. The way to that is to use a simple server program to make them available 'on the network' (even if just locally to your computer). The link in that above error message has a simple method - many IDE's, like VS Code or PyCharm, also have the ability to serve your files so the browser can access them.

Wow!! Great answer for stupid question. Very thank you for your kindness. I perfectly understand it. Thank you so mucj

@june9713 june9713 closed this as completed Aug 6, 2022
@marimeireles
Copy link
Member

No stupid questions!
I'm sure others are benefiting from it, thanks for asking @june9713 and for replying @JeffersGlass !

@marimeireles marimeireles removed the needs-triage Issue needs triage label Aug 16, 2022
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

3 participants