是否有可能在Chrome中运行本地Python代码? [英] Is it possible to run native python code in chrome?

查看:167
本文介绍了是否有可能在Chrome中运行本地Python代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在chrome中运行本地Python代码而不是javascript。
我看过像 pyjs brython ,但他们所做的是将python编译为javascript。虽然这些都是很棒的项目,但这种方法的问题始终是您无法轻易调试原始Python代码。



其中一些我偶然发现了线程,介绍如何为chromes-sandbox开发自定义代码。但这可能会导致在沙盒中实现一个python解释器,这将是一个矫枉过正的问题。



任何帮助表示赞赏! (我不想开始任何python与javascript的讨论,但只发现这是否可能,如果是这样,如何做到这一点)



亲切的问候,

Marco

解决方案

Python是一种编程语言,您不能运行本机代码一种编程语言。您可以在浏览器中运行使用python编写的程序。



那么我可以在浏览器中运行python代码吗?



2013年6月更新: Brython项目现已推出,可让您在浏览器中运行Python 3代码。您可以在 http://www.brython.info/ 上查看。



您可以使用使用ECMAScripten 在JavaScript中运行LLVM。这意味着您可以将C-python从C编译为JavaScript,并在浏览器中运行JS。到ECMAScripten wiki的链接提供了更多关于如何做到这一点的细节。



(这里是生活演示在浏览器中运行的python REPL)



还有在浏览器中工作的python 2 实现。



但我该怎么做?



可能不是,JavaScript和python在很多方面都很相似,都是动态的,既小巧又聪明。如果你知道python,你可以很快学习JavaScript。



如果你喜欢python的语法,你可以考虑 CoffeeScript ,它具有类似于Python的语法(并且有点像Ruby)并且透明地编译为JavaScript。

在浏览器中运行python的解决方案往往会慢得多,至少在更多的浏览器支持asm.js(目前只支持firefox每晚)之前。

I was wondering if it is possible to run native python code in chrome instead of javascript. I have seen projects like pyjs or brython, but what they do is compile python to javascript. While those are great projects a problem with this approach is always that you cannot easily debug the original python code.

Amongst other things I stumbled upon this thread, describing how to develop custom code for chromes-sandbox. But this would probably lead to implementing a python interpreter in the sandbox, which would be an overkill.

Any help is appreciated! (I don't want to start any python vs. javascript discussions, but only find out if this would be possible and if so, how to do it)

Kind Regards,
Marco

解决方案

Python is a programming language, you can't run native code of a programming language. You can however, run programs written in python in the browser.

So can I run python code in the browser or not?

Update June 2013: The Brython project is now available letting you run Python 3 code in your browser. You can check it out at http://www.brython.info/ .

You can use run LLVM in JavaScript using ECMAScripten. This means you can compile c-python from C to JavaScript and just run JS in the browser. The link to the ECMAScripten wiki provides more details on how to do that.

(Here is a live demo of a python REPL running in the browser)

There also exist python 2 implementations that work in the browser.

But should I?

Probably not, JavaScript and python are similar in many things, both are dynamic, both are compact and both are clever. If you know python you can learn JavaScript very quickly.

If you like python's syntax, you might want to consider CoffeeScript which has similar syntax to Python (and somewhat to Ruby) and compiles to JavaScript transparently.

Solutions that run python in the browser will also tend to be much slower, at least until more browsers will support asm.js (currently only firefox nightly).

这篇关于是否有可能在Chrome中运行本地Python代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆