是否可以从 Node.js 调用 .exe 文件中的函数?

问题描述 投票:0回答:1

是否可以从 Node.js 调用 .exe 文件中的函数?我最近使用 PyInstaller 将 Python 函数转换为 .exe 文件,现在我尝试从 Node.js 访问该函数。或者,是否有其他方法可以将 Python 脚本转换为与 Node.js 兼容的格式?”

请随意使用或根据您的喜好进行修改。

#python.py
def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    if b != 0:
        return a / b
    else:
        return "Cannot divide by zero"

我正在尝试从 Node.js 访问该函数

python node.js function exe
1个回答
0
投票

“在 .exe 中调用函数”可能不是正确的方法,除非您只想调用一个函数并且不想经常调用它。

但是,您可以使用

node-calls-python
模块:

import { interpreter as py } from 'node-calls-python'

const module = await py.load('./python.py')

console.log(await py.call(module, 'add', [1, 2])) // 3
© www.soinside.com 2019 - 2024. All rights reserved.