# Feature Request: GPIO Node Support Python3 Exclusives

**URL:** https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200
**Category:** General
**Created:** [15 June 2021 20:18 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200 "2021-06-15T20:18:51Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![garrenr14](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@garrenr14](https://discourse.nodered.org/u/garrenr14)
#### Post date: [15 June 2021 20:18 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/1 "2021-06-15T20:18:51Z")

</div>

Hello,

I have uninstalled Python2 on my Raspberry Pi and I am using Python3 only. I have an alias for python=python3 in place, which works in most cases. However, I noticed that the GPIO node no longer works as the underlying Python seems to want Python2.

I altered the GPIO node as follows to get it working again:

- Open file .../node\_modules/node-red-node-pi-gpio/nrgpio and change the last line to **python3** -u $BASEDIR/nrgpio.py $@
- Open file .../node\_modules/node-red-node-pi-gpio/nrgpio.py and change the first line to #!/usr/bin/ **python3**
- Open file .../node\_modules/node-red-node-pi-gpio/testgpio.py and change the first line to #!/usr/bin/ **python3**

I'm hoping that as the transition to Python3 moves foreword, this will become a standard practice for nodes that have underlying Python engines. At the very least, it would be nice if the GPIO javascript file would fall back to another Python script that calls out Python3 in the shebang.

Thanks!

---

<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: [15 June 2021 21:28 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/2 "2021-06-15T21:28:48Z")

</div>

Yes - in fact there is a beta version I would like to get feedback on 🙂

If you go into your ~/.node-red dir and run `npm i node-red-node-pi-gpio@2.0.0-beta3` that should grab the latest and you will see the nrgpio file now tries python3 first but falls back to python if not available.

---

<div class="post-metadata">

### Author: ![garrenr14](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@garrenr14](https://discourse.nodered.org/u/garrenr14)
#### Post date: [16 June 2021 14:57 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/3 "2021-06-16T14:57:13Z")

</div>

Thanks for the response! I did give that an install but I'm still seeing the node report 'not available'.

I think this is because the top line of both the file nrgpio.py and testgpio.py is `#!/usr/bin/python`. If I change that top line to say instead `#!/usr/bin/python3` then it works. I'm not sure how to make that fall back to Python2 however. There might need to be two identical scripts, just with different shebangs. Or, now that we're past the sunset date on Python2, just use the one shebang `#!/usr/bin/python3` in the next version of the node?

---

<div class="post-metadata">

### Author: ![garrenr14](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@garrenr14](https://discourse.nodered.org/u/garrenr14)
#### Post date: [16 June 2021 15:04 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/4 "2021-06-16T15:04:08Z")

</div>

...or the javascript could take the feedback from the shell script nrgpio to determine which Python is installed, and then in the javascript file itself just call out `child.spawn("/usr/bin/python3 " + pythonScript)` or `child.spawn("/usr/bin/python " + pythonScript)` respectively. Then you could completely eliminate the shebang in the python files and let the javascript force the interpretation?

---

<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: [17 June 2021 07:58 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/5 "2021-06-17T07:58:39Z")

</div>

the js file calls the nrgpio file that then calls the nrgpio.py file - as the shell script explicitly calls the python or python3 then the fact that the .py file has the shebang should be irrelevant. (so yes it could be removed - but does no harm)

---

<div class="post-metadata">

### Author: ![garrenr14](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@garrenr14](https://discourse.nodered.org/u/garrenr14)
#### Post date: [17 June 2021 17:11 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/6 "2021-06-17T17:11:23Z")

</div>

Oh I see. Then the same just needs to be done inside the js file for testgpio.py on line 12. Running `execSync(__dirname+'/testgpio.py');` yields the same problem of defaulting to Python2 I believe. Also I think the program would fail on lines 228 and 279 of the js file where the python is called directly like `node.child = spawn(gpioCommand+".py",...`

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [17 June 2021 17:52 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/7 "2021-06-17T17:52:44Z")

</div>

Could I just add 2 cents worth 🙂

You've un-installed python2 - I'm presuming on religious python grounds 🙂

AFAIK - RPi have always discouraged people from doing this, because of legacy dependency issues

I, for one, don't want the core developers having to do (unnecessary ) work just for that reason.

🙂

---

<div class="post-metadata">

### Author: ![garrenr14](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@garrenr14](https://discourse.nodered.org/u/garrenr14)
#### Post date: [17 June 2021 18:10 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/8 "2021-06-17T18:10:57Z")

</div>

Yup I agree. It's just a feature request and I appreciate your consideration. Looks like @dceejay is already halfway there though and I'm happy to see you're already anticipating these kinds of requests

---

<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: [17 June 2021 19:00 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/9 "2021-06-17T19:00:00Z")

</div>

ok have pushed beta4 for you to try please... tagged as `node-red-node-pi-gpio@next`

---

<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: [17 June 2021 19:02 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/10 "2021-06-17T19:02:33Z")

</div>

but yeah - I can't understand why they insist on leaving it called python3... if it is the preferred/supported version it should be aliased to python already... and leave python2 for any that really need it.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [17 June 2021 21:42 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/11 "2021-06-17T21:42:34Z")

</div>

The number of legacy programs that call python2 scripts just by assuming that python will run them means that it's better to leave things alone

A LOT of stuff would break if python suddenly meant python3

Defensive programming & KISS 🙂

---

<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: [17 June 2021 22:40 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/12 "2021-06-17T22:40:05Z")

</div>

> [@cymplecy](#):
>
> suddenly

?!? They’ve been deprecating it for 3-4 years now. It’s almost as bad as IE 😉

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [18 June 2021 05:10 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/13 "2021-06-18T05:10:31Z")

</div>

Not their own stuff - the programs developed by people like................... me! 🙂

---

<div class="post-metadata">

### Author: ![garrenr14](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@garrenr14](https://discourse.nodered.org/u/garrenr14)
#### Post date: [18 June 2021 14:02 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/14 "2021-06-18T14:02:48Z")

</div>

Thank you very much @dceejay , I have completed some tests with `node-red-node-pi-gpio@next` and it is working perfectly. I really appreciate your time on this, keep me updated for when it leaves beta!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [17 August 2021 14:03 UTC](https://discourse.nodered.org/t/feature-request-gpio-node-support-python3-exclusives/47200/15 "2021-08-17T14:03:06Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
