# Pythonshell use in Node-red

**URL:** <https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326>\
**Category:** General\
**Created:** [21 September 2018 09:23 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326 "2018-09-21T09:23:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chris/32/1328_2.png) [@Chris](https://discourse.nodered.org/u/Chris)\
**Post date:** [21 September 2018 09:23 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/1 "2018-09-21T09:23:23Z")

</div>

Dears,

I have installed pythonshell and want to exec BACpypres script. For example "\>python /home/pi/bacpypes/samples/RandomAnalogValueSleep.py --ini BACpypes,ini". However, I don't know how to do it correctly. Could you please help me solve it ?

Br,  
Chris

---

<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:** [21 September 2018 09:25 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/2 "2018-09-21T09:25:40Z")

</div>

> [@Chris](#):
>
> I don't know how to do it correctly.

So what have you tried so far?  
What keywords have you used in a search of the forum?

---

<div class="post-metadata">

**Author:** ![Chris](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chris/32/1328_2.png) [@Chris](https://discourse.nodered.org/u/Chris)\
**Post date:** [21 September 2018 09:39 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/3 "2018-09-21T09:39:06Z")

</div>

Hi zenofmud,

I cannot run the script in pythonshell and the result show "pyfile not exist".

[{"id":"16b51057.cf729","type":"pythonshell in","z":"41096a38.ae9594","name":"","pyfile":"/home/pi/bacpypes/samples/RandomAnalogValueSleep.py --ini BACpypes.ini","virtualenv":"/home/pi/bacpypes/","continuous":false,"stdInData":false,"x":340,"y":160,"wires":[["95fd053b.8b33d8"]]},{"id":"89192f8.b3c71d","type":"inject","z":"41096a38.ae9594","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":140.5,"y":76,"wires":[["16b51057.cf729"]]},{"id":"95fd053b.8b33d8","type":"debug","z":"41096a38.ae9594","name":"","active":true,"console":"false","complete":"false","x":537.5,"y":233,"wires":[]}]

---

<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:** [21 September 2018 10:22 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/4 "2018-09-21T10:22:50Z")

</div>

What keywords have you used in a search of the forum?

---

<div class="post-metadata">

**Author:** ![Chris](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chris/32/1328_2.png) [@Chris](https://discourse.nodered.org/u/Chris)\
**Post date:** [21 September 2018 14:44 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/5 "2018-09-21T14:44:23Z")

</div>

Yes. I search the "python" in the forum but I cannot find answer to solve it. I think the key point is that how to identify argv [argument]. Example: \>python /xxx/xxx/xxx/xxx.py --ini BACpypes.ini

---

<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:** [21 September 2018 14:49 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/6 "2018-09-21T14:49:52Z")

</div>

you might want to try the 'exec' node and pass the arguments to it.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [21 September 2018 15:08 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/7 "2018-09-21T15:08:49Z")

</div>

Using the exec node to run a python script works fine and I use NR to start a number of python scripts for various tasks. In addition, I like some of them to be started "visually", i.e. when I vnc into a headless RPi I want to see the script execution. To do this, I configure the exec node as shown below. In the example from my home automation systems I have four python scripts running in this way  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1a24b82206325357a199929ba2e916c25e563b42.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/87b12f7d65da38f45cfae8706409bdd8c92a43b1.png)

---

<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:** [21 September 2018 15:10 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/8 "2018-09-21T15:10:38Z")

</div>

If you still want to use the pythonshell node, you should read the documentation to see how to padd arguments, You might want to try the example flow the author provides.

---

<div class="post-metadata">

**Author:** ![Chris](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chris/32/1328_2.png) [@Chris](https://discourse.nodered.org/u/Chris)\
**Post date:** [24 September 2018 15:00 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/9 "2018-09-24T15:00:11Z")

</div>

Dears,

I also try to use exec node to run python script in windows OS. However it still have issue.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/715aefa2648e2bb889dcd7812be34d5be2fded2c.png)

[{"id":"a57ce9b6.631478","type":"exec","z":"59cea228.0dde9c","command":"python C:\bacpypes\RandomAnalogValueSleep.py --ini","addpay":true,"append":"C:\bacpypes\BACpypes.ini","useSpawn":"false","timer":"","oldrc":false,"name":"","x":500,"y":780,"wires":[["da47c202.50496"],["da47c202.50496"],["da47c202.50496"]]},{"id":"2d79e91a.e26fb6","type":"inject","z":"59cea228.0dde9c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":720,"wires":[["a57ce9b6.631478"]]},{"id":"da47c202.50496","type":"debug","z":"59cea228.0dde9c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":780,"wires":}]

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/160cf6acbd834de8815dc135dec753883c4dc480.png)

The correct command should be the follows,  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bb7e6a0284c9376e8cdeb569c9aca28411f6eafc.png)

---

<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:** [24 September 2018 15:29 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/10 "2018-09-24T15:29:05Z")

</div>

there seems to be quite a difference between the command you are using in the exec node vrs what you call the correct command. So does, from the command line, the command

```auto
python C:bacpypes/RandomAnalogValueSleep.py --ini C:bacpypes/BACpypes.ini

```

work\> I notice in the example where it works, bagpipes.ini is not in caps....

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [24 September 2018 18:16 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/11 "2018-09-24T18:16:21Z")

</div>

Sorry, I don't run Node-RED in Windows, only Linux

Maybe you need double backslashes in Windows (Like C:\\ etc etc)

---

<div class="post-metadata">

**Author:** ![Chris](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chris/32/1328_2.png) [@Chris](https://discourse.nodered.org/u/Chris)\
**Post date:** [29 September 2018 13:39 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/12 "2018-09-29T13:39:37Z")

</div>

It seems cannot identify arguments always show "unrecognized arguments". Below is my command in exec node for reference.

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0fe8b44b463cbde4b634c54fe4adaeec41f26928.png)

However it can be run well in command line as follows,

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6fe9ceaec5b000c784d8a7049005bfdc5850e01b.png)

[http://bacpypes.sourceforge.net/](http://bacpypes.sourceforge.net/)

---

<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:** [29 September 2018 14:11 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/13 "2018-09-29T14:11:50Z")

</div>

try unchecking the +Append [] msg.payload.

It looks like a timestamp is being passed - in msg.payload - to the exec node and is being added to the arguments.

---

<div class="post-metadata">

**Author:** ![Chris](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chris/32/1328_2.png) [@Chris](https://discourse.nodered.org/u/Chris)\
**Post date:** [8 October 2018 01:50 UTC](https://discourse.nodered.org/t/pythonshell-use-in-node-red/3326/14 "2018-10-08T01:50:16Z")

</div>

Thank you. After uncheck the +Append[] msg.payload it is correct now.
