Hello,
I have:
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.
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.
Most helpful comment
You cannot have a module named
zmq.py
because when youimport zmq
it will load yourzmq.py
instead of the installed pyzmq.