如何解决在我的 javascript 代码中使用 spawn 运行 python 时出现错误
我在 javascipt 中运行 pyhyon 脚本,但出现错误。
Javascript 代码:
const { spawn } = require("child_process");
const python = spawn(
"C:/Users/Murat/AppData/Local/Programs/Python/Python39/python.exe",["../pythonScript/main.py"]
);
python.stdout.on("data",function (data) {
console.log("It worked");
});
python.stderr.on("data",(data) => {
console.error("stderr: ",data.toString());
});
Python 代码:
import pandas as pd
dataset = pd.read_csv("Breast.csv")
print(dataset.shape)
错误: enter image description here
解决方法
您尝试访问的 csv 文件不存在或您当前的工作目录设置不正确。尝试将 import glob,os,shutil
source_folder = input("Please enter the path and name of the folder you want"
" to move. (E.g: C:/Users/myusername/Desktop/myphotos):"
"\n")
files = glob.iglob(os.path.join(source_folder,"*.jpg"))
print(source_folder)
move_folder = input("Do you want to move the folder and its contents? (Y/N) ").lower()
print(move_folder)
dest_folder = input("Please enter the destination path (E.g: C:/Users/myusername/folder1):"
"\n")
if not os.path.exists(dest_folder): #create folder if it doesn't exist
os.makedirs(dest_folder)
print(dest_folder)
if move_folder == "y":
print("Ok. Moving folder now.")
shutil.move(source_folder,dest_folder)
elif move_folder == "n":
print("Ok. Only moving files in the folder")
for file in files:
if os.path.isfile(file):
shutil.move(file,dest_folder)
print("Ok work complete")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。