我尝试在Vue.js CLI项目中运行以下代码,该项目使用python shell(节点模块)执行python文件:
methods: {
launchPy() {
let {PythonShell} = require('python-shell')
PythonShell.run('my_script.py', null, function (err) {
if (err) throw err;
console.log('finished2');
});
},
在“my_script.py”中,插入了以下代码:
f = open("demo.txt", "a")
f.write("Writing a file")
f.close()
当我运行localhost并通过botton click:launchPy()执行该方法时,会出现下一个错误:
[Vue warn]: Error in v-on handler: "TypeError: child_process_1.spawn is not a function"
我已经安装了node.js和pythonshell。即使我在一个单独的fileName.js文件中运行完全相同的函数launchPy()代码并执行'node fileName.js'命令,它也会平稳运行,实际上,python文件也会执行
我如何解决这个问题
目前没有回答
相关问题 更多 >
编程相关推荐