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

**URL:** <https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950>\
**Category:** General\
**Created:** [13 September 2021 08:56 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950 "2021-09-13T08:56:29Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [14 September 2021 04:25 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/21 "2021-09-14T04:25:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [14 September 2021 04:28 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/22 "2021-09-14T04:28:01Z")

</div>

@Colin

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 September 2021 07:22 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/23 "2021-09-14T07:22:23Z")

</div>

> [@Mansur](#):
>
> With command on terminal: echo $LD\_LIBRARY\_PATH
> 
> Output1:-  
> /usr/python/lib:/usr/lib:/usr/lib/iptables
> 
> With command on exec node: echo $LD\_LIBRARY\_PATH
> 
> Output2:-  
> code 0

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 September 2021 07:23 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/24 "2021-09-14T07:23:44Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [14 September 2021 14:30 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/25 "2021-09-14T14:30:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [14 September 2021 16:18 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/26 "2021-09-14T16:18:05Z")

</div>

> [@Colin](#):
>
> LD\_LIBRARY\_PATH=/usr/python/lib:/usr/lib:/usr/lib/iptables /usr/python/bin/python /home/pi/Downloads/telegram/FAhightemp.py

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de8fffc149626134e1a1d48a3ee425001b8ef052.png)

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da2e2d08b1844b65f0db562e6dbae4977f26125d.png)

> [@Colin](#):
>
> Also you still have not told us how node-red is started.

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 September 2021 16:49 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/27 "2021-09-14T16:49:32Z")

</div>

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

> [@Mansur](#):
>
> Then I pasted $PYTHONHOME on the terminal and I got  
> -ash: /usr/python: Permission denied, whereas this snapshot /usr/python/ shows permission 777

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 September 2021 16:50 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/28 "2021-09-14T16:50:07Z")

</div>

/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.

> [@Mansur](#):
>
> I did not understand this question, "how node-red is started"

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`

---

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [14 September 2021 17:21 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/29 "2021-09-14T17:21:00Z")

</div>

> [@Colin](#):
>
> 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).

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](https://IP:1880) manually.

> [@Colin](#):
>
> `ps -aux|grep node`

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.

---

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [14 September 2021 17:34 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/30 "2021-09-14T17:34:59Z")

</div>

A) CLI

> [@jbudd](#):
>
> **env \> /home/pi/env\_cli**

Gives no output.

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

> [@jbudd](#):
>
> **env \>/home/pi/env\_nr**

Gives code 0 nothing else.

Then

C) CLI within /home/pi directory

> [@jbudd](#):
>
> **ls -l env\_cli; cat env\_cli**

Gives

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

D) CLI within /home/pi directory

> [@jbudd](#):
>
> **ls -l env\_nr; cat env\_nr**

Gives:

````auto
-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```
````

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 September 2021 17:43 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/31 "2021-09-14T17:43:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [14 September 2021 17:51 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/32 "2021-09-14T17:51:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 September 2021 17:52 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/33 "2021-09-14T17:52:10Z")

</div>

> [@Mansur](#):
>
> > [@jbudd](#):
> >
> > **ls -l env\_cli; cat env\_cli**
> 
> Gives
> 
> `PYTHONPATH=/usr/python/lib:/usr/python/lib/stdlib:/usr/python/lib/python27.zip`

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.

---

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [14 September 2021 18:03 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/34 "2021-09-14T18:03:04Z")

</div>

> [@jbudd](#):
>
> ls -l env\_cli; cat env\_cli

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.

---

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [15 September 2021 05:55 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/35 "2021-09-15T05:55:51Z")

</div>

I found files on the system after executing the command

A) File env\_cli

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 September 2021 08:12 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/36 "2021-09-15T08:12:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Mansur](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mansur/32/47998_2.png) [@Mansur](https://discourse.nodered.org/u/Mansur)\
**Post date:** [16 September 2021 04:06 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/37 "2021-09-16T04:06:33Z")

</div>

> [@Colin](#):
>
> 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.

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:

> [@Colin](#):
>
> 1. Implement the python code directly in node-red. Is it doing anything complex?

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 😊

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 September 2021 09:14 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/38 "2021-09-16T09:14:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 September 2021 09:15 UTC](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950/39 "2021-09-30T09:15:15Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/nodered-python-error127-on-openwrt-bin-sh-python-not-found/50950.md?page=1)
