# ImportError: No module named 'zmq'

**URL:** <https://hub.mender.io/t/importerror-no-module-named-zmq/2682>\
**Category:** General Discussions\
**Created:** [October 16, 2020, 5:15pm UTC](https://hub.mender.io/t/importerror-no-module-named-zmq/2682 "2020-10-16T17:15:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamanRatna](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@SamanRatna](https://hub.mender.io/u/SamanRatna)\
**Post date:** [October 16, 2020, 5:15pm UTC](https://hub.mender.io/t/importerror-no-module-named-zmq/2682/1 "2020-10-16T17:15:28Z")

</div>

Hi guys,

I have a ArtifactInstall\_Enter\_01\_yes.py script as such,

```python
#!/usr/bin/python3

# Import libraries
import os, pwd
import zmq

# 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

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [October 16, 2020, 7:00pm UTC](https://hub.mender.io/t/importerror-no-module-named-zmq/2682/2 "2020-10-16T19:00:59Z")

</div>

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?

Drew

---

<div class="post-metadata">

**Author:** ![SamanRatna](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@SamanRatna](https://hub.mender.io/u/SamanRatna)\
**Post date:** [October 19, 2020, 3:58pm UTC](https://hub.mender.io/t/importerror-no-module-named-zmq/2682/3 "2020-10-19T15:58:11Z")

</div>

I used  
_sudo pip3 install zmq_.  
I have the latest version of the library.

I have tried,

#!/usr/bin/python3  
#!/usr/bin/python2  
#!/usr/bin/python  
#!/usr/bin/env python3

All of them give the same issue.

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [October 19, 2020, 6:33pm UTC](https://hub.mender.io/t/importerror-no-module-named-zmq/2682/4 "2020-10-19T18:33:56Z")

</div>

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?

Drew

---

<div class="post-metadata">

**Author:** ![SamanRatna](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@SamanRatna](https://hub.mender.io/u/SamanRatna)\
**Post date:** [October 20, 2020, 12:17pm UTC](https://hub.mender.io/t/importerror-no-module-named-zmq/2682/5 "2020-10-20T12:17:49Z")

</div>

I am using Raspbian for Raspberry Pi and Mender server is using Ubuntu.

import zmq is working fine from inside python3 on terminal. Using python2 on terminal, I get ‘no module named zmq’. I can’t understand, what’s going on

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [October 20, 2020, 2:52pm UTC](https://hub.mender.io/t/importerror-no-module-named-zmq/2682/6 "2020-10-20T14:52:35Z")

</div>

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
>>>
```
