1

My problem is as follows: I have written a python code, and I need to run it on a web page.Basically I need that whatever is on the console should be displayed as it is.

I have no experience in web development and similar libraries, and I need to get this done in a short time. Kindly tell how should I proceed?

Note: I might be plotting some graphs also. It would be great if they could be displayed all at once(sequentially) on the website

2 Answers2

0

https://brython.info/ https://skulpt.org/ https://pyodide.org/en/stable/

There are multiple python implementation on browser, some are webassemble some are javascript.

Is it a good idea to run python on browser as a replacement for javascript in 2022? No it is not, learn javascript. No in-browser python implementation can race with javascript as of today and most probably ever.

Işık Kaplan
  • 2,815
  • 2
  • 13
  • 28
-1

You Can't execute Python-Code directly inside a webbrowser - however, you could for instance create a basic IDE in HTML & JS, send code written by a user on the page to a Server, which would then run the code and send the results back to the client-page.

Unfortunately, such a project is quite ambitious and complicated, especially when Security & Stability are of mayor concern, as executing client-code is a very dangerous measure indeed, and requires expertise in Virtualization Techniques & Software.

Another Method could be to use a public API, which allows you to run Python code and fetch the results back. The procedure would be exactly the same as with the previous idea in terms of creating the web-client, but the heavy-lifting - which is actually executing the Python-code, would be taken care of for you.

As you can see, there is no concrete answer to this question, only suggestions.

A few useful links below:

https://docs.docker.com/

https://appdividend.com/2022/01/18/best-python-online-ide/

https://www.makeuseof.com/tag/programmer-browser-ides/

https://www.youtube.com/watch?v=og9Gaj1Hzag

How do I execute a string containing Python code in Python?

Bialomazur
  • 1,122
  • 2
  • 7
  • 18
  • 1
    This is incorrect. You definitely *can* run python in browser. Should you is a different question but you definitely can. – Işık Kaplan Feb 17 '22 at 03:30
  • @IşıkKaplan I don't know of any browser with an embedded Python-Interpreter, could you name an example? – Bialomazur Feb 17 '22 at 03:31
  • There doesn't have to be an embedded interpreter for you to be able to run python. Do checkout my answer. It has several links. – Işık Kaplan Feb 17 '22 at 03:35
  • @IşıkKaplan Still no "real" CPython, ports to WebAssembly or JS emulations etc. Those are fine when Performance is not of concern, but (I may be wrong) I highly doubt that those will perform even close to as well as the real thing. – Bialomazur Feb 17 '22 at 03:38
  • What does "real" mean? Just because the implementation is written in wasm, doesn't make it any less python. – Işık Kaplan Feb 17 '22 at 03:51
  • 1
    By your logic, pypy is also not python because it is not cpython, cpython is a c implementation, granted the reference implementation, but an implementation of the rules of the language. Python doesn't mean cpython. – Işık Kaplan Feb 17 '22 at 03:54
  • 2
    What's the Python specification say about built in functions like `open`, for example? Are they optional? A Wasm or JS implementation that runs in the browser would be presumably be sandboxed and not have full access to the filesystem. – GordonAitchJay Feb 17 '22 at 05:50