运行时错误 - 在离子3中执行python脚本时找不到模块“子进程”

时间:2021-07-06 15:29:30

I'm going to execute a python script through an Ionic 3 application in the button click event. I have used Python-shell in order to accomplish this task.

我将在按钮单击事件中通过Ionic 3应用程序执行python脚本。我使用Python-shell来完成这项任务。

Below is my code snippet in 'home.ts'.

下面是'home.ts'中的代码片段。

import { PythonShell } from 'python-shell';

 rundata(){
  PythonShell.run('C:/ChathuS/PycharmProjects/Profiling module new/Profiling module/data.py', function (err) {
    if (err) throw err;
    console.log('Executed data.py');
  });}

In the 'home.html', I use a button click event to call the above function as follows.

在'home.html'中,我使用按钮单击事件来调用上述函数,如下所示。

 <button ion-button (click)="rundata()" *ngIf="facebook.loggedIn">  
    <ion-icon name="logo-facebook"></ion-icon>  Analyse profile 
 </button>

运行时错误 - 在离子3中执行python脚本时找不到模块“子进程”

This gives me following error in the browser.

这使我在浏览器中出现以下错误。

How to solve this issue?

如何解决这个问题?

1 个解决方案

#1


0  

You cannot do this in client side , you need to understand this

你不能在客户端这样做,你需要了解这一点

You wan't to bundle your code for the browser, and the browser doesn't know about processes and child processes.

您不想为浏览器捆绑代码,浏览器也不知道进程和子进程。

at most write your web services and make get/post request and implement your python code there.

最多编写您的Web服务并发出get / post请求并在那里实现您的python代码。

Check this out if you still want to do this

如果你还想这样做,请检查一下

Git

#1


0  

You cannot do this in client side , you need to understand this

你不能在客户端这样做,你需要了解这一点

You wan't to bundle your code for the browser, and the browser doesn't know about processes and child processes.

您不想为浏览器捆绑代码,浏览器也不知道进程和子进程。

at most write your web services and make get/post request and implement your python code there.

最多编写您的Web服务并发出get / post请求并在那里实现您的python代码。

Check this out if you still want to do this

如果你还想这样做,请检查一下

Git