ModuleNotFoundErr

hello,everyone
i meet problem about python lib import
i use the exec node to execute a pyhton file which imports paho.mqtt.client
when i enter python3 xxx.py in terminal,it can run normally but in node-red it has moduleNotFoundError:No module named 'paho'
the way i use node-red is by entering 'sudo node-red start' in terminal

Why do you do that? That will start node-red with a flows file called start.json which is a bit unusual. What OS/hardware are you running on? Did you look at the node red docs Getting Started guide for the recommended way of installing and running node-red on your OS?

The problem is probably down to the path that python uses to find modules, but I don't think that is a problem that most users have when running python in an exec mode so I would start by making sure node-red is installed correctly and you are starting it correctly.

I also have to ask why you need the python paho mqtt client when Node-RED already has MQTT nodes as part of the core set....

thank u very much
i change the start way it doesn't report error any more
i used to start by command "sudo node-red"
now i use "sudo systemctl enable nodered.service" it works well

the mqtt broker needs the data that periodically generated from the python file as soon as possible
i guess sending the data directly may be a little faster?