# Pythonshell help? "exit code: -4058"

**URL:** <https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419>\
**Category:** General\
**Created:** [31 January 2019 06:37 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419 "2019-01-31T06:37:44Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [31 January 2019 06:37 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/1 "2019-01-31T06:37:44Z")

</div>

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 "test.py" whose content is just:

print("Hello.")

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:  
 ![node-redflow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b4945a3af4c26cae8a9b6b1d5b96f98a116a31ea.jpeg)

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.

---

<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:** [31 January 2019 09:10 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/2 "2019-01-31T09:10:17Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [31 January 2019 10:04 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/3 "2019-01-31T10:04:59Z")

</div>

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:  
 ![pythonerrornodered](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4b48084c97ce2daa41151847728679d3d2151eb7.jpeg)

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:  
C:\Users\Username\AppData\Local\Programs\Python\Python37

And my node-red path is:  
C:\Users\Username\.node-red

---

<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:** [31 January 2019 10:18 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/4 "2019-01-31T10:18:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [31 January 2019 10:32 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/5 "2019-01-31T10:32:50Z")

</div>

Hi, Colin

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

python "D:\file\_directory\myfile.py"

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

---

<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:** [31 January 2019 10:39 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/6 "2019-01-31T10:39:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [31 January 2019 11:08 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/7 "2019-01-31T11:08:42Z")

</div>

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 "test.py" file to Python's directory over on  
C:\Users\Username\AppData\Local\Programs\Python\Python37

and changed the py file in the node properties of pytonshell to  
C:\Users\Username\AppData\Local\Programs\Python\Python37\test.py

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 test.py since it has been moved to Python's directory, but alas no luck as well.

---

<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:** [31 January 2019 11:14 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/8 "2019-01-31T11:14:04Z")

</div>

> [@LuluMomo](#):
>
> Now all that's left is how to make the pythonshell node work

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.

---

<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:** [31 January 2019 11:19 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/9 "2019-01-31T11:19:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [31 January 2019 11:47 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/10 "2019-01-31T11:47:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [31 January 2019 11:53 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/11 "2019-01-31T11:53:25Z")

</div>

Hi, dceejay.

By adding path, you mean adding path of python.exe  
C:\Users\Username\AppData\Local\Programs\Python\Python37

to the "path" in the environment variables here?  
 ![nodered-environmentvar](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8bfe1c314ee6ed5455d9dfebdf567cbda2f39df4.jpeg)

---

<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:** [31 January 2019 11:53 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/12 "2019-01-31T11:53:40Z")

</div>

> [@dceejay](#):
>
> You probably need to add the path to your python executable to your operating system path. (Outside of Node-RED)

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

---

<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:** [31 January 2019 12:19 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/13 "2019-01-31T12:19:18Z")

</div>

> [@LuluMomo](#):
>
> By adding path, you mean adding path of python.exe  
> C:\Users\Username\AppData\Local\Programs\Python\Python37

Yes, I believe so.

> [@LuluMomo](#):
>
> Can exec node take arguments from an inject node too?

Yes. You can append the payload to the command.

---

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [31 January 2019 12:35 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/14 "2019-01-31T12:35:02Z")

</div>

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!

> [@Colin](#):
>
> Yes. You can append the payload to the command.

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!

---

<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:** [31 January 2019 14:16 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/15 "2019-01-31T14:16:21Z")

</div>

> [@LuluMomo](#):
>
> I can now execute python from the terminal without having to go to Python's directory,

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?

---

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [31 January 2019 14:46 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/16 "2019-01-31T14:46:27Z")

</div>

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.

> [@Colin](#):
>
> Is it the same user running node-red as you logged into in the terminal?

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:

C:\Users\my\_name.node-red  
C:\Users\my\_name\AppData\Local\Programs\Python\Python37

---

<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:** [31 January 2019 14:50 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/17 "2019-01-31T14:50:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LuluMomo](https://avatars.discourse-cdn.com/v4/letter/l/8e7dd6/32.png) [@LuluMomo](https://discourse.nodered.org/u/LuluMomo)\
**Post date:** [1 February 2019 03:47 UTC](https://discourse.nodered.org/t/pythonshell-help-exit-code-4058/7419/18 "2019-02-01T03:47:02Z")

</div>

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! 😄
