Pyzmq: AttributeError: module 'zmq' has no attribute 'Context'

Created on 7 Oct 2017  路  3Comments  路  Source: zeromq/pyzmq

Hello,

I have:

  • Windows 10 64-bit;
  • Python 3.6.3 for Windows 64-bit with all debugging related stuff;
  • ZeroMQ-4.0.4-miru1.0-x64;
  • pyzmq (16.0.2)
    (I installed it via "pip install pyzmq --install-option="--zmq=bundled"". Also tried just "pip install pyzmq")

Then I copy/pasted example of using ZMQ from here http://zguide.zeromq.org/py:hwserver
`import time
import zmq

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")

while True:
# Wait for next request from client
message = socket.recv()
print("Received request: %s" % message)

#  Do some 'work'
time.sleep(1)

#  Send reply back to client
socket.send(b"World")

`

and got error message

g:\proj\python\tests>python zmq.py Traceback (most recent call last): File "zmq.py", line 8, in <module> import zmq File "g:\proj\python\tests\zmq.py", line 10, in <module> context = zmq.Context() AttributeError: module 'zmq' has no attribute 'Context'

Could you please help with resolving that issue? Thanks in advance.

Most helpful comment

You cannot have a module named zmq.py because when you import zmq it will load your zmq.py instead of the installed pyzmq.

All 3 comments

You cannot have a module named zmq.py because when you import zmq it will load your zmq.py instead of the installed pyzmq.

When I am replacing
import zmq
with
import pyzmq
I am getting
ModuleNotFoundError: No module named 'pyzmq'

Also there is a list of packages installed on my comp;

C:\Python\Python36\Lib\site-packages>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
btfxwss (1.1.1)
mysql-connector-python (2.1.7)
mysqlclient (1.3.12)
pip (9.0.1)
pyzmq (16.0.2)
setuptools (36.5.0)
six (1.11.0)
websocket-client (0.44.0)

It looks like I've found the reason of such behavior. Previously I erroneously installed zmq with pip and some files left after that installation. When I removed that folder completely from 3d-party packages folder and re-installed pyzmq everything starts working.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

badrobit picture badrobit  路  8Comments

kozo2 picture kozo2  路  7Comments

f0t0n picture f0t0n  路  3Comments

stuaxo picture stuaxo  路  15Comments

cs01 picture cs01  路  4Comments