# How to install node red and recognizer

**URL:** <https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249>\
**Category:** General\
**Created:** [22 October 2023 07:50 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249 "2023-10-22T07:50:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 07:50 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/1 "2023-10-22T07:50:51Z")

</div>

Hello everyone!  
My question would be with what rights  
install node red, google recognizer, python3 so that there are no dependencies. Because it is in node red, e.g. the bigexec node, from which I run a python script that uses google recognizer and portaudio. However, citing the node red portaudio error and the recognizer error, it cannot run the python script. The mentioned python script works perfectly both from the console and from thonny. Thus, I think that legal errors will definitely occur. So how do I install the above software to make everything good?  
Thank you very much for your help!

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 October 2023 08:08 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/2 "2023-10-22T08:08:15Z")

</div>

> [@azxo1](#):
>
> The mentioned python script works perfectly both from the console and from thonny.

> [@azxo1](#):
>
> bigexec node ... cannot run the python script.

Most likely you have a mistake in your bigexec node config.

1. How do you run the script from the console?
2. Why do you want to use bigexec rather than the standard exec node?
3. Show us your bigexec node settings.
4. What error do you get?

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 08:21 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/3 "2023-10-22T08:21:28Z")

</div>

1, sudo /home/xy.py  
2, same error with exec node. I tried pythonshell node, but the ENV permission was the error there as well. I can run other python scripts (simpler ones)  
3, Command: python3 /home/xy.py , Use shell, Payload is : an input. (I've already tried several settings)  
4, a, `raise PortAudioError(errormsg, err) sounddevice.PortAudioError`

```
  b, `Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1513

```

Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection\_In )' failed in 'src/hostapi/alsa/pa\_linux\_alsa.c', line: 2813`

```
 c, `audio = r.listen(source)

```

File "/usr/local/lib/python3.9/dist-packages/speech\_recognition/ **init**.py", line 465, in listen`  
and more.....

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 08:33 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/4 "2023-10-22T08:33:50Z")

</div>

Run exec: `/home/xy.py: line: 2: import: command not found`

....

```auto
Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1513
Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection_In )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2813
Traceback (most recent call last):
  File "/home/GalZoli/pisokjo.py", line 22, in listen1
    audio = r.listen(source)
  File "/usr/local/lib/python3.9/dist-packages/speech_recognition/ __init__.py", line 465, in listen

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 October 2023 08:48 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/5 "2023-10-22T08:48:09Z")

</div>

> [@](#):
>
> How do you run the script from the console?  
> sudo /home/xy.py

If you run it from the console without sudo does it give an error?

/home/xy.py is an unusual location for a script file since /home generally belongs to root.  
It would be more common to find scripts in your home directory `/home/<username>`

I infer that the file xy.py is executable: `ls -l /home/xy.py` shows **-rwxrwxr-x**  
What is the first line of the file, the hashbang line to specify it's a python 3 script?  
I _think_ it should be `#! /usr/bin/python3`

No doubt there are good reasons for the existence of bigexec & pythonshell nodes, but I've not yet found a need for either. 😀

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 08:56 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/6 "2023-10-22T08:56:14Z")

</div>

In addition, the script runs continuously, does not stop, Recognizer is constantly listening for the keyword. Maybe the solution would be if the python script starts (delayed) after the start of the raspberry, so it should not be started from node red. The script has a .txt output, which I read in node red. However, this way I would have to give up a complicated mechanism, according to which in node red flow, I don't only monitor the keyword, because chatGPT also monitors it. It's quite complicated, both the flow and the script, but the point is that the "smart home" responds to certain keywords and acts, and after a certain keyword I can ask chatGPT a question, which answers, both verbally and saved to a into a separate text file. So I can speak with chatGPT, all in Hungarian. The condition for this is that the python code runs, e.g. from thonny. But the perfect thing would be if I could start it from node red.

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 08:58 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/7 "2023-10-22T08:58:55Z")

</div>

Of course: `/home/<username>` , but I didn't want to write the user here. And yes: `#! /usr/bin/python3`

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 09:04 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/8 "2023-10-22T09:04:50Z")

</div>

I'm sure (maybe) that node red, or python, or recognizer was not installed with good privileges, so node red can't access some things. I tend to reinstall everything from 0, including raspberry, so that everything is good. Would it be a solution if everything is sudo su? or should I root the user? Or: `sudo npm config set unsafe-perm true`

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 October 2023 09:13 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/9 "2023-10-22T09:13:51Z")

</div>

I asked if running the script from the command line without sudo gives an error because you don't have sudo in your bigexec config.

> [@azxo1](#):
>
> the script runs continuously ...

I don't understand all of that, particularly how the python output gets into NR and Chat.  
However there is a node-red-node-daemon to launch long running background commands.

> [@azxo1](#):
>
> Would it be a solution if everything is sudo su? or should I root the user?

In my opinion that would be a really bad idea. Using sudo and root unnecessarily can cause problems in the future (which might be what you are experiencing now!)  
If you reinstall OS and everything, try not to use elevated privileges. A linux machine should really be able to run day to day tasks without sudo.

> [@azxo1](#):
>
> Or: `sudo npm config set unsafe-perm true`

Sorry I have no idea what that would do.

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 09:22 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/10 "2023-10-22T09:22:33Z")

</div>

As I mentioned, the script works perfectly from command line and thonny. also with sudo. If I start the script from the command line (sudo /home/pi/xy.py or thonny), I get the text spoken into the microphone in ned red in read node, which I then process.  
(and not chat but speak)  
(((google translate))) 🙂

Tried sudo in bigexec but failed to set password ☹

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 October 2023 09:37 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/11 "2023-10-22T09:37:21Z")

</div>

> [@azxo1](#):
>
> Tried sudo in bigexec but failed to set password ☹

You could run the python script as root using systemd (which allows you to delay it's start until other services are running) or /etc/rc.local.  
Or allow passwordless sudo.  
Or find a way to allow everything to run without sudo (ie reinstall)

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 09:40 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/12 "2023-10-22T09:40:32Z")

</div>

Or find a way to allow everything to run without sudo (ie reinstall)

😉  
Yes, that's exactly what I would ask, how to reinstall everything so that everything gets all permissions

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 12:05 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/13 "2023-10-22T12:05:17Z")

</div>

without sudo :

```auto
xy@raspberrypigal:~ $ python3 /home/xyUSER/xy.py
you said: Helló
you said: please
you said: kiskacsa
you said: Nógrád étterem
you said: Nógrád
you said: node red
you said: Miskolc
you said: Hány fok van Miskolcon

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 October 2023 12:59 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/14 "2023-10-22T12:59:42Z")

</div>

```auto
python3 /home/xyUSER/xy.py

```

Well that's not exactly the same as "sudo /home/xyUSER/xy.py without the sudo". You have bypassed the hashbang line there.

> [@azxo1](#):
>
> Run exec: `/home/xy.py: line: 2: import: command not found`

This looks like it's not python trying to interpret the script but Bash, which might happen if your hashbang is not the first line in the script file or has some invalid syntax.

ps You have already posted the apparent real pathname of the script.

---

<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:** [22 October 2023 13:31 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/15 "2023-10-22T13:31:12Z")

</div>

> [@azxo1](#):
>
> Would it be a solution if everything is sudo su? or should I root the user? Or: `sudo npm config set unsafe-perm true`

No, you would just be creating more future problems.

> [@azxo1](#):
>
> Tried sudo in bigexec but failed to set password

You need correctly sort the permissions FIRST, not try to continue with bad settings.

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 14:40 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/16 "2023-10-22T14:40:08Z")

</div>

> [@TotallyInformation](#):
>
> You need correctly sort the permissions FIRST

Yes! That's what I'm asking! What is the correct permission setting? Because running via ssh from a terminal or raspberry pi Thonny, the python script works great. (entered in terminal as user pi) But the script does not run from node red or with sudo. I just tried running it from rc.local and crontab and sudo crontab after a reboot, but the script still won't run.

```auto
xy@raspberrypigal:~ $ sh /home/pi/autostart.sh
you said: Helló
you said: mizu
you said: hány óra

```

```auto
xy@raspberrypigal:~ $ sudo sh /home/pi/autostart.sh
[sudo] xy jelszava:
Traceback (most recent call last):
  File "/home/pi/xy.py", line 2, in <module>
    import sounddevice
ModuleNotFoundError: No module named 'sounddevice'

```

Running on exec node:

```auto
: Error terminating PortAudio: PortAudio not initialized [PaErrorCode -10000]

```

```auto
Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1513
Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection_In )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2813

```

...etc

---

<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:** [22 October 2023 15:09 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/17 "2023-10-22T15:09:03Z")

</div>

> [@azxo1](#):
>
> What is the correct permission setting?

I can't say based on the information available. At a guess though, I'd say that the user running the Node-RED service probably doesn't have the appropriate rights for the audio device(s). Looks like something is trying to link to ALSA at least.

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [22 October 2023 15:11 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/18 "2023-10-22T15:11:41Z")

</div>

yes, ALSA is possible

---

<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:** [22 October 2023 15:13 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/19 "2023-10-22T15:13:35Z")

</div>

Try running a command line tool from Node-RED that uses ALSA, if that fails, make sure that the Node-RED user is added to the appropriate security group.

Probably the `audio` group.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [22 October 2023 15:22 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/20 "2023-10-22T15:22:43Z")

</div>

> [@azxo1](#):
>
> ```auto
> xy@raspberrypigal:~ $ sh /home/pi/autostart.sh
> you said: Helló
> you said: mizu
> you said: hány óra
> 
> ```
> 
> ```auto
> xy@raspberrypigal:~ $ sudo sh /home/pi/autostart.sh
> [sudo] xy jelszava:
> Traceback (most recent call last):
> File "/home/pi/xy.py", line 2, in <module>
> import sounddevice
> ModuleNotFoundError: No module named 'sounddevice'
> 
> ```

You keep changing the way you are running it and each new version is giving you different errors.

Now we see that the python module "sounddevice" is installed for the logged in user, which might be "pi" and might be "GalZoli" but it is not installed globally.  
You might think that the way to fix it is `sudo pip install sounddevice` but I think it's so messed up that you should:

1. Reinstall the operating system.
2. Reinstall Node-red using a particular username.
3. Install any required python modules for that same username.
4. Make your script executable.
5. Using the same username get the program running from the command line without sudo, sh, python, intermediate Bash scripts or other jiggery-pokery.
6. Check that it will run from Node-red exec node without sudo.
7. Use node-red-node-daemon if you want it running all the time.

[Next page](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249.md?page=2)
