Python 3 function & Node-red disconnected

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. :frowning:

26 Jan 22:31:44 - [info] Server now running at 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 ? :roll_eyes: 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.

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.

1 Like

Thank you for the reply.

Yes, I have installed Python3.

Due to above trial now I cannot run node-red. :frowning: 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.

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

1 Like

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.

2 Likes

Hi ,

I tried to run nodered using powershell command 'node-red' but still I cannot :frowning: , 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)

What trial and what was the result?

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 :frowning:

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

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.

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

Result - Disconnected nodered with above message

## 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 ! :slight_smile:

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

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

python/python3 confusing :hushed:

anyway finally i was able to reopen nodered with node-red new.json :smiley: 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 :thinking:

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

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

[{"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":[]}]

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
  •   + 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

seems like no python. :no_mouth: 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 :frowning:

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.

Installing python is something for google to answer.

1 Like

It is not clear :frowning: 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

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.

1 Like