# draw on default display regardless where run from
# script mandatory for having access to raspberry pi
# missing these lines give 'execution format error'
os.environ["DISPLAY"] = ":0"
pwstruct = pwd.getpwnam("pi")
os.setgid(pwstruct.pw_uid)
os.setuid(pwstruct.pw_gid)
# mandatory to add context to a socket
context = zmq.Context()
# enable socket as REQUEST
socket = context.socket(zmq.REQ)
# Open port for connection and make sure it is not default port like 8888, 50
socket.connect("tcp://localhost:5558")
print("Sending request ...")
# Send message via the port
socket.send(b"New Update")
This gives me the following error in Mender server log
ImportError: No module named ‘zmq’
I have installed zmq from root on my device. What could be the problem ?
Thanks in advance.
Saman
You are explicitly running python3 so you need to make sure that the python3 version of the library is installed.
How did you install the library? Can you share the exact commands used?
Hmm. What OS/Distro/Build system are you using? It sounds like something is not right in the pip configuration.
Do you get an error if you just run “python3” manually and then enter “import zmq” at the REPL?
Sounds like you have the python3 version of zmq but not the python2 version.
I just installed a fresh raspbian and was able to find zmq in both python2 and python3 with the following
pi@raspberrypi:~$ sudo apt update
pi@raspberrypi:~$ sudo apt install python-pip python3-pip
pi@raspberrypi:~$ pip2 install zmq
pi@raspberrypi:~$ pip3 install zmq
pi@raspberrypi:~$ python2
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zmq
pi@raspberrypi:~$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import zmq