Thursday, April 7, 2022

[SOLVED] /bin/sh: 1 : conda: not found error when executing a conda run command through a nodejs script using pm2

Issue

Introduction

I am running a nodejs server in the production environment using pm2. The javascript file a python script upon a prompt using the conda run method. This command errors out with the following message: /bin/sh: 1: conda: not found. However, running the same js file using npx nodemon or simply node works well without any errors.

Detailed Description

The javascript file is as follows

...
command = "conda run -n p2vois python  path_to_python_script_file.py "+variable_with_arguments_for_the_python_script;
...
var pyProcess = cmd.get(command,
                (err, datax, stderr)=> {
                        console.log("here datax: %s", datax)
                        if(err){
                            console.log("python script cmd error: " + err)
                        }
                        else{
                            ...
                        }

This code upon running using the sudo pm2 start server.js command gives an error as follows:

python script cmd error: Error: Command failed: conda run -n p2vois python path_to_python_script_file.py arguments_for_the_python_script
/bin/sh: 1: conda: not found

However, running the same javascript file server.js with npx nodemon or node does not give any error.

Possible causes of error

I believe the cause should be conda trying to run the command through /bin/sh instead of /bin/bash. Another reason could be an underlying path issue while running with pm2. I do not know how to fix this error, so any help would be appreciated.


Solution

Solution

Just removed the sudo privilege for the pm2 command and the code started working again.



Answered By - starc52
Answer Checked By - Mary Flores (WPSolving Volunteer)