如何从 Javascript 执行 Python 脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5327485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:49:20  来源:igfitidea点击:

How can I execute a Python script from Javascript?

javascriptpythongoogle-chrome

提问by Apps

I have written a module in python which performs some function.

我在 python 中编写了一个模块,它执行一些功能。

I then created a Google Chrome extension which makes use of JSON and javascript.

然后我创建了一个使用 JSON 和 javascript 的 Google Chrome 扩展。

Now when I click on the extension I want it to execute the python program which is stored on my hard disk and display the output on the browser again.

现在,当我单击扩展程序时,我希望它执行存储在我硬盘上的 python 程序并再次在浏览器上显示输出。

Is there a way in which I can do this??

有没有办法做到这一点?

采纳答案by dLobatog

Repeated :

重复 :

Calling Python from JavaScript

从 JavaScript 调用 Python

Here you have some answers, Pyjamas is probably the best option in your case

在这里你有一些答案,睡衣可能是你的最佳选择

回答by user2335278

Probably a late reply but a possible solution is to make your python script act as a server and let the browser plugin interact with it.

可能回复较晚,但可能的解决方案是让您的 python 脚本充当服务器并让浏览器插件与之交互。

回答by c-ram

forgive me if i'm incorrect on infinite proportions.

如果我在无限比例上不正确,请原谅我。

I believe that JavaScript is executed in a sandboxed/ isolated environment. Therefore you cannot invoke a python interpreter* or any other executable residing on the system.

我相信 JavaScript 是在沙盒/隔离环境中执行的。因此,您不能调用 python 解释器*或驻留在系统上的任何其他可执行文件。

*unless the interpreter itself were written in javascript.

*除非解释器本身是用 javascript 编写的。