encoding error in PythonShell when using pyinstaller and cx-freeze

33 views Asked by At

I am using python-shell for integrating my machine learning model in my application. python-shell requires python installed or python executables. So i am trying to convert my python script into exe using pyinstaller. But it gave the error as follows:

PythonShellError: SyntaxError: Non-UTF-8 code starting with '\x90' in file C:\Users\jayan\OneDrive\Documents\KMIT\PS\Thyroid Detection\WebApp\server\ML_model\build\exe.win-amd64-3.11\deployment_g63.exe on line 1, but no encoding declared; see https://peps.python.org/pep-0263/ for details

my node.js code for integrating:

const { PythonShell } = require("python-shell");

const predictForm = async (req, res) => {
    try {
        const dataToPredict = req.body;
        delete dataToPredict.Name;

        const modelPrediction = async (data) => {
            const options = {
                mode: "text",
                scriptPath: "./ML_model/build/exe.win-amd64-3.11",
                args: JSON.stringify(data),
            };
            return new Promise((resolve, reject) => {
                PythonShell.run("deployment_g63.exe", options).then((results) => {
                    try {
                        const prediction = JSON.parse(results[0].replace(/'/g, '"'));
                        resolve(prediction);
                    } catch (error) {
                        console.log("Error in parsing the data", error);
                        reject(error);
                    }
                }).catch((err) => {
                    console.log("Error in executing the Python script: ", err);
                    reject(err);
                });
            });
        };

        const prediction = await modelPrediction(dataToPredict);
        res.json({prediction });

    } catch (error) {
        console.log("error error",error);
        res.status(500).json({ error: "Internal Server Error" });
        return;
    }
};

module.exports = { predictForm };

I have tried another modules like cx-freeze and py2exe for converting it into python executable. I am getting error with py2exe. With cx-freeze, I am getting the same error as pyinstaller. Please help me with this.

0

There are 0 answers