# Python 3 function & Node-red disconnected

**URL:** <https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275>\
**Category:** General\
**Created:** [26 January 2019 17:18 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275 "2019-01-26T17:18:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 17:18 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/1 "2019-01-26T17:18:02Z")

</div>

Hello,

I installed python 3 using **npm install -g node-red-contrib-python3-function** & just inject a simple code to print 'hello'.

Suddenly node-red disconnected with below message in PowerShell. Though I tried to run node-red after that, it is not working. ☹

**26 Jan 22:31:44 - [info] Server now running at [http://127.0.0.1:1880/](http://127.0.0.1:1880/)**  
**26 Jan 22:31:44 - [warn]**

**---------------------------------------------------------------------**  
**Your flow credentials file is encrypted using a system-generated key.**

**If the system-generated key is lost for any reason, your credentials**  
**file will not be recoverable, you will have to delete it and re-enter**  
**your credentials.**

**You should set your own key using the 'credentialSecret' option in**  
**your settings file. Node-RED will then re-encrypt your credentials**  
**file using your chosen key the next time you deploy a change.**  
**---------------------------------------------------------------------**

**26 Jan 22:31:44 - [info] Starting flows**  
**26 Jan 22:31:44 - [info] [python3-function:e1d01315.61c6e] Python function '' running on PID undefined**  
**26 Jan 22:31:44 - [info] Started flows**  
**26 Jan 22:31:44 - [red] Uncaught Exception:**  
**26 Jan 22:31:44 - Error: spawn python ENOENT**  
\*\* at Process.ChildProcess.\_handle.onexit (internal/child\_process.js:232:19)\*\*  
\*\* at onErrorNT (internal/child\_process.js:407:16)\*\*  
\*\* at process.\_tickCallback (internal/process/next\_tick.js:63:19)\*\*

What is this issue ? 🙄 What should I want to do? Since this is my first time trying function with python 3 I could not figure out the issue correctly. Kindly help me in this regard.

I believe that I can use python in node-red for my project instead of javascript. If it is difficult in any situation kindly let me know. I'm scared that whether I will be stuck in the middle.

Thank you.

---

<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:** [26 January 2019 17:34 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/2 "2019-01-26T17:34:12Z")

</div>

> [@emspe](#):
>
> node-red-contrib-python3-function

Have you installed Python3?  
However since there has been no feedback on the open issues on the node for two years it does not appear that it is maintained, which is not a good sign. If it is just that you don't want to learn javascript then don't worry, if you know any languages then picking up js will not be difficult.

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 17:43 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/3 "2019-01-26T17:43:21Z")

</div>

Thank you for the reply.

Yes, I have installed Python3.

Due to above trial now I cannot run node-red. ☹ The above mentioned same issue is happening when I run the 'node-red' command in PowerShell. Unable to connect node-red. Yeh, I better try js.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [26 January 2019 17:49 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/4 "2019-01-26T17:49:14Z")

</div>

If you haven't got any flows you want to save, change the name of your flows file and restart node-red

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 January 2019 17:58 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/5 "2019-01-26T17:58:22Z")

</div>

Hmmm - I see they also say to install globally (-g) - which in general is not necessary and can cause difficulties...

Outside of Node-RED - can you call python or do you have to call python3 ? That node seems to just call python - so if your command is python3 you may need to alias it.

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 18:18 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/6 "2019-01-26T18:18:28Z")

</div>

Hi ,

I tried to run nodered using powershell command 'node-red' but still I cannot ☹ , Below is the message I receive all the time in powershell.

* * *

## 26 Jan 23:45:21 - [info] Starting flows 26 Jan 23:45:21 - [info] [python3-function:e1d01315.61c6e] Python function '' running on PID undefined 26 Jan 23:45:21 - [info] Started flows 26 Jan 23:45:21 - [red] Uncaught Exception: 26 Jan 23:45:21 - Error: spawn python ENOENT at Process.ChildProcess.\_handle.onexit (internal/child\_process.js:232:19) at onErrorNT (internal/child\_process.js:407:16) at process.\_tickCallback (internal/process/next\_tick.js:63:19)

---

<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:** [26 January 2019 18:21 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/7 "2019-01-26T18:21:36Z")

</div>

> [@emspe](#):
>
> Due to above trial now I cannot run node-red

What trial and what was the result?

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 18:22 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/8 "2019-01-26T18:22:20Z")

</div>

hello ,

Thank you for the reply.

Yes I can call it as python. I used above mentioned command and installed. Then the node appeared in my pallet list. When i used it , it caused to disconnect node-red ☹

Since I'm new to Node-red I have no idea about fixing this..

---

<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:** [26 January 2019 18:24 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/9 "2019-01-26T18:24:38Z")

</div>

If you uninstall the arduino node again then node-red should run. It will complain about the missing node but the UI will work so you can remove that node from the flow.

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 18:25 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/10 "2019-01-26T18:25:33Z")

</div>

Trial - Installed using **npm install -g node-red-contrib-python3-function** / inject a simple code to print 'hello'

Result - Disconnected nodered with above message

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 January 2019 18:27 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/11 "2019-01-26T18:27:35Z")

</div>

```auto
## 26 Jan 23:45:21 - Error: spawn python ENOENT

```

is saying that it can't find a command called python... so are you sure it can call python from the command line (and not python3 ?)

you can start Node-RED `node-red new.json` to start it with a flow called new.json... and that will be a blank flow... and / or you could open the flow\_{some name}.json file in your user directory (usually .node-red) and then copy it... then back in the blank flow - menu - import from clipboard. which should bring back in your flows... but delete that node before hitting deploy ! 🙂

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 18:30 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/12 "2019-01-26T18:30:46Z")

</div>

I'm sorry i forgot to mention that , I'm working with windows.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 January 2019 18:39 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/13 "2019-01-26T18:39:13Z")

</div>

Also try uninstalling that node. Then reinstall it without the -g

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 18:46 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/14 "2019-01-26T18:46:35Z")

</div>

python/python3 confusing 😯

anyway finally i was able to reopen nodered with node-red new.json 😃 thank you very much for that. aandd.. it looks like this.. Still, I can see that node "python 3 function" & I'm scared...

Again thank you for helping to recover nodered. but still Im confused about using python in nodered 🤔

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 January 2019 18:57 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/15 "2019-01-26T18:57:03Z")

</div>

At the command line where you start Node-RED - what does the command

```auto
python --version

```

report ?

Here is a small flow to import and try - this uses the exec node to try to call python instead - so will show in the debug sidebar what is working or not

```auto
[{"id":"60fe5876.31e658","type":"inject","z":"68704546.3d0e0c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":580,"wires":[["c6973a2a.03d2b8"]]},{"id":"c6973a2a.03d2b8","type":"exec","z":"68704546.3d0e0c","command":"python -u -c \"for r in range(10): print 'hello world'\"","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":450,"y":580,"wires":[["d813f234.bc0ae"],["29e08e44.0441a2"],[]]},{"id":"d813f234.bc0ae","type":"debug","z":"68704546.3d0e0c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":560,"wires":[]},{"id":"29e08e44.0441a2","type":"debug","z":"68704546.3d0e0c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":600,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 19:16 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/16 "2019-01-26T19:16:51Z")

</div>

## python --version \> command reports below

python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.  
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.  
At line:1 char:1

- python --version
- 

```auto
  + CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
  + FullyQualifiedErrorId : CommandNotFoundException

```

* * *

instead, I tried \> **py -V** and it shows

Python 3.7.2

After the flow it says as below

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/89374919b2f0d28a4e7e63028d75000429d86e72.png)

seems like no python. 😶 but how to install? when I run the previous command it appears as below.

npm install -g node-red-contrib-python3-function

- node-red-contrib-python3-function@0.0.4  
updated 1 package in 9.288s

without -g

npm install node-red-contrib-python3-function  
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\package.json'  
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\package.json'  
npm WARN No description  
npm WARN No repository field.  
npm WARN No README data  
npm WARN No license field.

- node-red-contrib-python3-function@0.0.4  
updated 1 package and audited 451 packages in 6.888s  
found 0 vulnerabilities

* * *

How to slove this ☹

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [26 January 2019 19:22 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/17 "2019-01-26T19:22:20Z")

</div>

One issue is you are not in your node-red directory when you are trying to install. You can ignore warnings they are not errors.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 January 2019 19:35 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/18 "2019-01-26T19:35:38Z")

</div>

Installing python is something for google to answer.

---

<div class="post-metadata">

**Author:** ![emspe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emspe/32/5421_2.png) [@emspe](https://discourse.nodered.org/u/emspe)\
**Post date:** [26 January 2019 19:51 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/19 "2019-01-26T19:51:25Z")

</div>

It is not clear ☹ How to install it correctly?  
After i executed the nodered by entering 'node-red' command in powershell,  
I opened another powershell and tried below separately.

**npm install -g node-red-contrib-python3-function**

**npm install node-red-contrib-python3-function**

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [26 January 2019 20:41 UTC](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275/20 "2019-01-26T20:41:24Z")

</div>

You are getting somewhat confused between the different components.

Firstly you need to get Python working correctly - currently it is not and that is the core of your issue.

You should be able to start python from the command line using the command `python`. Depending which vendor's version of python you have installed, possibly it hasn't given you this option but instead has given you the `py` command.

Assuming that `py` = `python`, you could try setting up an alias in your PowerShell configuration. Or, create a link or junction from `py` to `python`. Third method would be to create a command called `python.cmd` and in it, make it call `py`.

Once you can run python by issuing the command `python`, the python node should start to work.

[Next page](https://discourse.nodered.org/t/python-3-function-node-red-disconnected/7275.md?page=2)
