Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run native python code in chrome?

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

like image 270
Marco Pashkov Avatar asked May 06 '13 23:05

Marco Pashkov


People also ask

Can you run Python code on chrome?

Go to the chrome web store to download the Python Shell Chrome Extension. Click on add to chrome to install and add the extension to the browser. After the extension is installed, click on it to launch it. A small window will appear where you can write and execute the python code.

Can you run Python code on a browser?

Brython is both a Python compiler and an interpreter written in JavaScript. As a result, you can compile and run Python code in the browser. A good example of this feature is demonstrated by the online editor available on the Brython website. With the online editor, Python is running in the browser.

How do I open a Python project in chrome?

Open chrome://extensions and press developer mode. Press “load unpacked extension”, select your directory and press ok.


1 Answers

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).

like image 178
Benjamin Gruenbaum Avatar answered Oct 11 '22 15:10

Benjamin Gruenbaum