如何在 nodejs 应用程序中部署和 运行 python 脚本?

How to deploy and run python scripts inside nodejs application?

我正在使用一个 MEAN 堆栈应用程序,它将一个文件传递给 python 脚本,这个脚本执行一些任务然后它 returns 一些结果。 问题是部署时如何安装所需的 python 包?

谢谢!

我已经尝试 运行 python nodejs 应用程序中的代码,使用 python shell.

  • 将 python 脚本与 requirements.txt(具有您的 python 依赖项)一起放置在您的 nodejs 项目中 目录。
  • 在部署期间,在 requirements.txt 上调用 pip install 并且它 应该为您安装软件包。

  • 您可以像任何 shell 命令一样从 nodejs 调用 python 脚本 使用内置 child_process 模块或 python-shell.