I have nodered on OpenWRT and have configured exec node to exexute a python code. python /path/xxx.py. The path is correct. The command works fine on CLI. But from nodered exec node throws an error 127, /bin/sh: python not found. Please advise what is the solution?
Welcome to the forum @Mansur.
Probably the python command is not in the PATH that is in use when node-red is running. Put the full path to python in the exec node. You can run
to find that out, which will probably say somethning like
/usr/bin/python, so in the exec node put
Is /path/xxx.py an executable file?
Is the first line of /path/xxx.py a valid "hashbang" eg #! /usr/bin/python3 ?
Then exec /path/xxx.py directly not as a parameter to python.
Thanks for your reply. Yes the xxx.py is executable (chmod +x) and I have inserted #! /usr/bin/python3 on top of the python file but it still does the same. error 127. My nodered version is 1.2.9.
Do we have any other suggestion? The file is owned by root:root, does it make a difference? All other commands are working on "exec" node such as reboot, touch etc but refusing to execute python.
What are the exact settings of your exec node?
What does ls -l /path/xxx.py give you?
The error is saying that python is not found therefore, as @colin said - you need to specify the full path to python.
Have you tried what Colin suggested?
I somehow missed @Colin reply but I tried it - which python - reveals /usr/python/bin/python which is strange. I put this on the top of the python code as well as on the exec node as /usr/python/bin/python /path/xxx.py (deploy) but results in the same error, also tried after reboot but same error. "/usr/python/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory"
Also tried @jbudd suggestion ls -l /path/xxx.py reveals -rwxr-xr-x 1 root root 1991 Sep 13 18:52 /home/pi/Downloads/telegram/FAhightemp.py
Trying to send high temperature alert Telegram App message to my phone. It works from CLI command but fails on Node-Red exec node command.
Gave a try /usr/python /home/pi/Downloads/telegram/FAhightemp.py, says permission denied.
[quote="Mansur, post:7, topic:50950"]
/usr/python/bin/python /path/xxx.py (deploy) but results in the same error
Does that command work in a terminal?
I don't believe that it results in exactly the same error, in node-red. Can you show us the error?
[quote="Mansur, post:7, topic:50950"]
"/usr/python/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory"
[/quote] - (edited/ error added subsequently)
CLI command works perfectly everytime:-
How are you configuring the
The path to python should be in the
Command option and the path to the python program. Should be in the
append option with the
msg.option checked off.
Here is the snapshot
This is a LoRaWAN Gateway with OpenWRT on eMMC. I installed pip upgrade and telepot in this manner, not sure if this could cause this?
pip install --upgrade pip
pip install telepot
pip in /mnt/mmcblk0p1/pysdk/lib/python2.7/site-packages (20.3.4)
telepot in /mnt/mmcblk0p1/pysdk/lib/python2.7/site-packages (12.7)
I hesitate to say so but it seems fundamentally wrong to run a program by specifying the interpreter on the command line.
Command /home/pi/Downloads/telegram/FAhightemp.py and
append blank, or any CLI parameters required by FAhightemp.py, none in this case.
Still, so far as I know it should work either way.
I wonder if you have installed python libraries just for a single user - "root" but Node-Red exec runs as "pi".
Only a guess based on you having a /home/pi directory.
Not sure how to check that. Perhaps from the command line sudo -u pi /home/pi/Downloads/telegram/FAhightemp.py ?
OpenWRT did not have pi as a directory but it was created by me since I had flow for raspberry pi previously made and wanted to use here. Also OpenWRT does not use sudo. It also does not recognise the -u command (tried without sudo).
I am familiar with raspberry pi but this LoRaWAN Gateway with OpenWRT (not raspberry pi) is the first time use for me. Never used OpenWRT before nor am I familiar with users. In contact with the manufacturer but no help on this python issue so far and that is why decided to post it on Nodered forum.
Generally when I login with root credentials, I get root@GATEWAY:~#, however there are different credentials to login gateway configuration cum nodered on the inherent webpage. You are right I have installed python at the root command promt. In short root credentials are different from nodered platform credentials. Does this indicate that python libraries are installed as root and nodered is working as a user, is that what you mean?
That's what I'm wondering but it's all speculation because I don't have an openwrt machine to experiment with.
So not the same error as previously. It is finding the python program now, but as has suggested it is not finding the libraries for some reason. You have not done as I asked, which was to confirm that the command you are now using still works from the command line.
I expect it still to work but that needs to be confirmed.
How are you running node-red?
Ok. I fully understand.
Exec node takes all other commands such as reboot, touch etc. Is there any other way or any other script that I can use (shell script on exec node, wild guess) to trigger python scripts on the back ground since it works perfectly when executed on the terminal.
Yes on the terminal (CLI) this command also works fine.
root@GATEWAY:~# /usr/python/bin/python /home/pi/Downloads/telegram/FAhightemp.py
Node-red is run with a button on the gateway configuration page or https://IP:1880 with different credentials than root. Is that what you are looking for?
That doesn't run node-red, that just opens a browser viewing it. The question is, how is node-red itself started? I don't know openwrt so I don't know about any button. It would be good to know what user is running node-red, but I suspect that it is root as probably there isn't any other user.
In a terminal what does
echo $LD_LIBRARY_PATH show?
If that shows something, then if you run that command in an exec node what does it show?
With command on terminal: echo $LD_LIBRARY_PATH
With command on exec node: echo $LD_LIBRARY_PATH
@jbudd The program running is Python and it runs the users python script.
You can use an
change node and put the command and the options you are using in msg.payload and leave the
Command option in the
exec node blank