question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

imports do not work in script inside html and from browser does not work in external files

See original GitHub issue

I was trying to move your example calculator code to an external .py file, but ‘from browser’ did not work, since there’s no such library. I installed ‘pip install brython’, which did not help.

Then I tried importing a different python class inside the html python script, however, it did not work either. The other file lies in the same root directory where the requesting code is. What can be wrong?

`

<body onload="brython()"> <script type="text/python"> from calculator import * # this causes a ModuleNotFoundError: calculator from browser import document, html </script> </body> `

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
PierreQuentelcommented, Jul 2, 2020

I close the issue, assuming that the script runs when loaded from a web server. If it’s not the case don’t hesitate to reopen it.

1reaction
PierreQuentelcommented, Jun 25, 2020

To avoid the formatting problem in this issue tracker, you should use the markdown syntax for code, here put the code between lines starting with ```

Read more comments on GitHub >

github_iconTop Results From Across the Web

External javascript file not working in HTML file - Stack Overflow
The first solution is to put your JS file after the second one is to put the function call inside the window onload...
Read more >
How to Load External JavaScript Files From the Browser ...
Here is how to import JavaScript without a <script> tag directly from Firefox or Chrome's development console.
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >
EP33 - Importing JavaScript into HTML via Script tag
Importing an external JavaScript file into your HTML page ... This will cause issues and will likely end in your script NOT being...
Read more >
HTML script src Attribute - W3Schools
If you want to run the same JavaScript on several pages in a web site, you should create an external JavaScript file, instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found