Execute python code inside browser without Jython

最后都变了- 提交于 2019-12-18 11:47:51

问题


Is there a way to execute python code in a browser, other than using Jython and an applet?

The execution does not have to deal with anything related to graphics. For example, just sum all the digits of a binary 1Gb file (chosen by the browser user) and then return the result to the server.

I am aware that python can be executed remotely outside a browser, but my requirement is to be done inside a browser.

For sure, I take for granted the user will keep the right to execute or not, and will be asked to do so, and all this security stuff... but that is not my question.


回答1:


The Pyjamas project has a compiler called pyjs which turns Python code into Javascript.




回答2:


nosklo's answer is wrong: pyxpcomext for firefox adds language="python" support to script tags. yes it's a whopping 10mb plugin, but that's life. i think it's best if you refer to http://wiki.python.org/moin/WebBrowserProgramming because that is where all known documented links between python and web browser technology are recorded: you can take your pick, there.




回答3:


I put together a table comparing many Python-In-Browser technologies not long ago: http://stromberg.dnsalias.org/~strombrg/pybrowser/python-browser.html




回答4:


On my travels, I came across Skulpt, a project which seems to offer Python directly in the browser without plugins. It's licensed under MIT.

Skulpt Homepage

Skulpt @ Github




回答5:


No, you can't.

Modern browsers only run javascript or plugins. You can develop your own python plugin and convince people to download and run it, but I guess that falls to the "not inside the browser" category.




回答6:


You mean client-side?

Sure you can! But you need to have python installed on the client first.

The linked book describes that in order to use client-side Active Scripting, you can test it with the a simple html file.

<html><body>
<script language='Python'>alert("Hello, Python!")</script>
</body></html>

In the old version refered in that book (Python programming on Win32 By Mark Hammond, Andy Robinson) it says that you need to install the Python Win32 extensions, and it will automatically register Python Active Scripting. Should you do it manually, you have to run the script python\win32comext\axscript\client\pyscript.py.




回答7:


http://repl.it/ - Python interpreter in JavaScript running on client side. There are many other languages too. Source is available under MIT license, which is awesome.




回答8:


You can now (2016) also use:

http://www.transcrypt.org

It compiles Python 3.6 (incl. multiple inheritance, operator overloading, all types of comprehensions, generators & iterators) to lean and fast JS, supports source level debugging with sourcemaps and optional static typechecking using mypy.

Disclaimer: I am the initiator of the project.




回答9:


By accident I was listening to Hanselminutes where he mentioned about Gestalt project. This is a solution to integrate a languages as IronRuby and IronPython in browser via Silverlight.

So I think the answer is no if you don't have any special plugins.




回答10:


Brython - "A Python 3 implementation for client-side web programming"

  • http://www.brython.info/
  • https://bitbucket.org/olemis/brython/src


来源:https://stackoverflow.com/questions/1235629/execute-python-code-inside-browser-without-jython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!