Pythonshell help? "exit code: -4058"


Hello, I'm new to NodeRed and Pythonshell in general so forgive me if this question sounds "noob-ish". I tried to display a message using Pythonshell from "" whose content is just:


I'm expecting "Hello." to pop up in the debug message, however everytime I deploy the flow and click inject, it always shows "exit code: -4058". I'm kind of stuck...

Here's my flow:

I have tried searching Google and this forum but I can't seem to find any problem similar to mine. I also have tried reinstalling the pythonshell node but it didn't solve the problem. I appreciate any kind of help. Thank you in advance!

EDIT (Feb 1, 2019):
Thanks to Colin, and dceejay, this problem is finally solved. All you have to do is to add Python's executable path to the path in Environment Variables, accessible from Control Panel > System > Advanced system settings > Environment Variables.



Are you sure you have python installed ?
Just installing the node won't install it for you.
I'm not familiar with that node as it's not one of the core ones.
You can do similar with the built in exec node calling out to python.
This simple flow should test it for you

[{"id":"360a45a8.41fdba","type":"exec","z":"9da3d17d.f408","command":"python -c","addpay":false,"append":"\"print('hello');\"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":360,"y":1240,"wires":[["57ed0121.b1d11"],["232a8f6c.0ffd4"],[]]},{"id":"f163f832.e34d18","type":"inject","z":"9da3d17d.f408","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":1240,"wires":[["360a45a8.41fdba"]]},{"id":"57ed0121.b1d11","type":"debug","z":"9da3d17d.f408","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":1220,"wires":[]},{"id":"232a8f6c.0ffd4","type":"debug","z":"9da3d17d.f408","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":1260,"wires":[]}]


Hi, dceejay
Thank you for replying! Yes, I have Python 3.7 installed. I tested the flow you gave me (thank you!) and it returned this error:

Does this have something to do with where I installed Python? I didn't do any modification when installing and just went with the default install. My Python 3.7 path is:

And my node-red path is:



Whan you run a command from the terminal window, if so what command do you use? Normally this would be something like python



Hi, Colin

Thank you for replying! Yes, I use that command. Although mine goes like this:

python "D:\file_directory\"

because my .py files are located over at D: .



If you use exactly that command to run it then for some reason the exec node can't find the command. I don't know about Windows so don't know how that should work. There may be a better way in Windows but if you find whereabouts the python command is installed and in the exec node instead of putting just python put the full path to the command c:/something/python then that might do it.



Hi, Colin
Oooh the exec node does work if I put the full path to the command! Thank you for your help!
Now all that's left is how to make the pythonshell node work, hmm...

I tried moving the "" file to Python's directory over on

and changed the py file in the node properties of pytonshell to

but it didn't work. It still returns "exit code: -4058,". I also tried to change the py file in the node properties to just since it has been moved to Python's directory, but alas no luck as well.



What does that give you that the exec node doesn't?
edit It's probably the python command it is not finding, not your file.



You probably need to add the path to your python executable to your operating system path. (Outside of Node-RED)



Hi, Colin.
I'm not sure actually. I'm new to all of these. Can exec node take arguments from an inject node too?

I'm just still curious about why pythonshell just refuses to work on my computer. My friend's pythonshell works fine. I did try asking him but he didn't have any idea about it.



Hi, dceejay.

By adding path, you mean adding path of python.exe

to the "path" in the environment variables here?



Though when he runs python from a terminal it finds it, which suggests that the path in node-red is different.



Yes, I believe so.

Yes. You can append the payload to the command.



Hi, Colin.

Ok, I've added the path to the environment variables. Unfortunately, pythonshell still refuses to work... Though, I can now execute python from the terminal without having to go to Python's directory, so that's nice!

That's neat! Ok, if all else fails, I'll just use the exec node then.

Maybe I'll try asking my lecturer tomorrow about pythonshell. I'll update this thread if he has any solution for it. In the meantime, thank you very much for your help!



You didn't tell us before that in the terminal it did not find the python command unless you went to that folder. Try the exec node without the full path to python. If that still doesn't work then the Path in node-red must be different to path from the terminal. Is it the same user running node-red as you logged into in the terminal?



Hi, Colin.

I'm sorry, my bad. I have tried the exec node without the full path to Python and it didn't work. So I think it's as you say: the path in node-red is different to the path from the terminal. I'm not quite sure how you change path in node-red though. I might have to do some Googling in that case.

I'm not sure, but besides Window's generated folder in the "Users" folder (Public, and Default), I'm the only user on my computer. Both node-red's and Python's directory is under my user folder though. Here's their directory:




Just a thought, did you restart node-red after you changed the path?



Hi, Colin.

Sorry for the late reply. I just woke up. I think I forgot to restart Node-Red after changing the path because now, after restarting it, the exec node works even if I don't include the full path to Python! The pythonshell node also works now!

I'm so glad! I need them to work in order to start working on my undergrad thesis! Thank you very much, Colin, and @dceejay for your help on this matter! :smile:

1 Like