Nodered python error127 on OpenWRT /bin/sh: python not found

Used inject node to insert msg.payload filled with command and left exec node empty with msg.payload ticked. It still throws the same error.

@Colin

Please highlight what does this suggest comparing Output1 and Output2 by your experience? Does it give us any clue to the problem?

I don't understand what you mean by output 1 and output 2. When you run it in a terminal there is no output 1 and output 2. Please copy/paste the result of running it in the terminal.

When you run it in an exec node there are three outputs. What is on each output?

[Edit] or do you mean that when you run it in the terminal you see the path shown, but when you look at output 1 of the exec node it shows an empty payload?

If that is the case then this may be the problem, that the library load path is not setup. Try this as the command.
LD_LIBRARY_PATH=/usr/python/lib:/usr/lib:/usr/lib/iptables /usr/python/bin/python /home/pi/Downloads/telegram/FAhightemp.py
Don't add any extra spaces into the first bit.

Also you still have not told us how node-red is started.

@zenofmud while the points you are making are valid, I don't think the method of invoking the command will change whether python can find its libraries. Or am I missing something?

I just wanted to make sure that the user understood how the exec node works

I get the following on the three outputs of exec node, and this time it is code:1

image

Then I pasted $PYTHONHOME on the terminal and I got
-ash: /usr/python: Permission denied, whereas this snapshot /usr/python/ shows permission 777

image

I did not understand this question, "how node-red is started" my apology. How do I check this? please elaborate so I can check and message

Are you shrinking your screen captures before pasting them? It's making my eyes hurt trying to read the error message.

That is because /usr/python is a directory.
By typing $PYTHONHOME you are asking the shell to execute the file whose path name is the value of that variable.
You can't execute a directory. The "x" permission has different meanings for directories and files.

We have not established if Node-Red is running as root or another user.
Can you run the following command from the commandline:
env > /home/pi/env_cli
And this from Node-Red exec
env >/home/pi/env_nr

Then from the command line
cd /home/pi
ls -l env_cli; cat env_cli
ls -l env_nr; cat env_nr

Copy and paste the output here.

/usr/python is a folder. The python program is in /usr/python/bin/python.

It still is not finding the python libraries for some reason.

Somehow the node red server is started running. Either you do that manually or it is configured to run automatically on boot. It may be useful to know how that is done. Presumably you installed node red somehow and set it up to start on boot, or you start it manually somehow. So tell us how you installed it and how you set it up to start on boot (if you have done that).

What does this command show. It should tell us the user that is running node-red.
ps -aux|grep node

Nodered came as a feature on the LoRaWAN Gateway, I did not install it. Nodered (systemd I guess) starts on its own. I then manually open the web interface https://IP:1880 manually.

The command prompt says invalid option for -aux so I just tried p | grep node and the output is:-

root@GATEWAY:~# ps |grep node 2340 root 938m S node-red 6952 root 3852 S grep node root@GATEWAY:~#

I guess this shows it is running as root.

Does this answer the question, I will be glad to troubleshoot further.

A) CLI

Gives no output.

B) This on exec node and all three outputs connected to debug:-

Gives code 0 nothing else.

Then

C) CLI within /home/pi directory

Gives

PYTHONPATH=/usr/python/lib:/usr/python/lib/stdlib:/usr/python/lib/python27.zip

D) CLI within /home/pi directory

Gives:

-rw-r--r--    1 root     root           373 Sep 14 19:26 env_nr
procdT_J_V_instances=object
SHLVL=2
HOME=/
procdJSON_CUR=J_T1
PYTHONUNBUFFERED=1
procdT_J_V_script=string
NTBA_FIX_319=1
procdJ_V_name=node_red
TERM=linux
procdJ_V_instances=J_T1
PATH=/usr/sbin:/sbin:/usr/bin:/bin
procdK_J_V= name script instances
procdJ_V_script=/etc/rc.d/S66node_red
NODE_RED_HOME=/usr/lib/node_modules/node_red
procdK_J_T1=
PWD=/
procdT_J_V_name=string```

Did you manually create the /home/pi folder or did you create a user called pi?

You are correct. I created /home/pi/Downloads/ directory manually. I normally use Raspberry Pi to install Nodered using bash script and I have old flows which already have nodes directing to files behind /home/pi/Downloads/. I therefore decided to mkdir /home/pi/Downloads/ so I do not have to change all my nodes on the flow for this particular Non-Raspberry Pi Gateway. This gateway uses OpenWRT as OS did not have /home/pi directory. I think this one does not have any other user other than root, but I am not sure about it and do not know how to check it. I always end up on the root when I login SSH.

Well I'm completely mystified. There seems to be no environment set up when you are logged in as root.
ls -l env_cli gives no output, not even an error message.

But there is an environment within Node-Red and it doesn't include PYTHONPATH.

However it does all show that the process run by exec is root.

Maybe your enquiries in the openwrt forum will be more fruitful.

Oops!!

When I separate the two commands at the colon then ls -l env_cli

gives
-rw-r--r-- 1 root root 474 Sep 14 19:41 env_cli

Yes I have put the same query on OpenWRT forum in parallel and it is in a similar situation. Have not reached a solution.

I found files on the system after executing the command

A) File env_cli

SSH_CLIENT=192.168.1.104 53185 22
USER=root
LD_LIBRARY_PATH=/usr/python/lib:/usr/lib:/usr/lib/iptables
SHLVL=2
OLDPWD=/root
TERMINFO=/etc/terminfo
HOME=/
SSH_TTY=/dev/pts/0
PS1=\[\e]0;\u@\h: \w\a\]\u@\h:\w\$ 
LOGNAME=root
TERM=linux
PATH=/usr/sbin:/sbin:/usr/bin:/bin
PYTHONUSERBASE=/usr/pyuser/app
SHELL=/bin/ash
PYTHONHOME=/usr/python
PWD=/
SSH_CONNECTION=192.168.1.104 53185 192.168.1.115 22
PYTHONPATH=/usr/python/lib:/usr/python/lib/stdlib:/usr/python/lib/python27.zip

and

B) env_nr

procdT_J_V_instances=object
SHLVL=2
HOME=/
procdJSON_CUR=J_T1
PYTHONUNBUFFERED=1
procdT_J_V_script=string
NTBA_FIX_319=1
procdJ_V_name=node_red
TERM=linux
procdJ_V_instances=J_T1
PATH=/usr/sbin:/sbin:/usr/bin:/bin
procdK_J_V= name script instances
procdJ_V_script=/etc/rc.d/S66node_red
NODE_RED_HOME=/usr/lib/node_modules/node_red
procdK_J_T1=
PWD=/
procdT_J_V_name=string

Do these reveal anything? libraries? path? etc

Possibly setting all the python related env vars in the node-red startup script (or setting them when you call the python command) would fix it.

Alternative approaches are

  1. Change the python code into a continuously running service that you pass data to/from node-red using, for example, MQTT.
  2. Implement the python code directly in node-red. Is it doing anything complex?

Bingo, path to PYTHONHOME, PYTHONPATH and LD_LIBRARY_PATH needed to be added to the OpenWRT node_red daemon. Upon stop and start, the exec node command worked perfectly.

Thank you @Colin, @jbudd, @zenofmud for your kind inputs.

BTW, on another note, I also tried the below method on Raspberry Pi Buster OS as an alternative:

with the help of flow on the link https://flows.nodered.org/flow/778859ca2503db35ff0e12341508efef/in/vL27qorhYRSn and created virtual python env in a directory of my choice. It worked, this is for the benefit of the future readers. Readers to care in particular about inserting the absolute path of the directory of their choice in all the example nodes and .sh files on the given flow. Hurray :blush:

2 Likes

By implementing it in node-red I meant translating it to node red nodes and/or javascript, so that you would not need to use Python at all.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.